HTML
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false" OnRowCommand="OnRowCommand">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:TemplateField HeaderText="Country">
<ItemTemplate>
<asp:Label ID="lblCountry" Text='<%# Eval("Country") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton Text="Select" ID="lnkSelect" runat="server" CommandName="Select" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
Id
</td>
<td>
Name
</td>
<td>
Country
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtId" runat="server" />
</td>
<td>
<asp:TextBox ID="txtName" runat="server" />
</td>
<td>
<asp:TextBox ID="txtCountry" runat="server" />
</td>
</tr>
</table>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
GridViewRow row = ((e.CommandSource as LinkButton).NamingContainer as GridViewRow);
txtId.Text = row.Cells[0].Text;
txtName.Text = row.Cells[1].Text;
txtCountry.Text = (row.FindControl("lblCountry") as Label).Text;
}
}
Namespace
using System.Data;