Study this example and adapt it to your need:
the aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default30.aspx.cs" Inherits="Default30" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="Label1" runat="server" Text="Check"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</form>
</body>
</html>
the code behind:
using System;
using System.Web.UI.WebControls;
using System.Data;
public partial class Default30 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == true)
return;
DataTable dtTemp = new DataTable();
dtTemp.Columns.Add("Name");
dtTemp.Rows.Add("Peter");
dtTemp.Rows.Add("James");
dtTemp.Rows.Add("Mick");
dtTemp.Rows.Add("MAry");
GridView1.DataSource = dtTemp;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chkBox = (CheckBox)row.FindControl("CheckBox1");
if (chkBox != null && chkBox.Checked)
{
ListBox1.Items.Add(row.Cells[1].Text.ToString());
chkBox.Checked = false;
}
}
}
}