Study this example and adapt to your need:
the aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default31.aspx.cs" Inherits="Default31" %>
<!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>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>
the code behind:
using System;
using System.Web.UI.WebControls;
using System.Data;
public partial class Default31 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == true)
return;
DataTable dtTemp = new DataTable();
dtTemp.Columns.Add("Student ID");
dtTemp.Columns.Add("First Name");
dtTemp.Columns.Add("Last Name");
dtTemp.Rows.Add("1", "Peter", "Leow");
dtTemp.Rows.Add("2", "James", "Song");
dtTemp.Rows.Add("3", "Mick", "Sam");
dtTemp.Rows.Add("4", "MAry", "Cool");
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)
{
TextBox1.Text = row.Cells[2].Text.ToString();
}
}
}
}