Hi Tevin,
Refer below sample.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Employee Code">
<ItemTemplate>
<asp:LinkButton ID="EmployeeCode" OnClick="EmployeeCode_Click" runat="server" Text='<%# Eval("Id") %>'
CommandArgument='<%# Eval("Id") %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
CS.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Id", typeof(int)), new DataColumn("Name", typeof(string)), new DataColumn("Country", typeof(string)) });
dt.Rows.Add(1, "Mudassar Khan", "India");
dt.Rows.Add(2, "John Hammod", "USA");
dt.Rows.Add(3, "Robert Mathew", "France");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void EmployeeCode_Click(object sender, EventArgs e)
{
LinkButton lnk = sender as LinkButton;
GridViewRow row = (GridViewRow)lnk.NamingContainer;
Response.Redirect("Default.aspx?Id=" + lnk.CommandArgument + "&Name=" + row.Cells[1].Text);
}
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
lblId.Text = "Id is : <b> " + Request.QueryString["Id"] + "</b>";
lblName.Text = "Name is :<b> " + Request.QueryString["Name"] + "</b>";
}
VB.Net
VB.aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("Id", GetType(Integer)), New DataColumn("Name", GetType(String)), New DataColumn("Country", GetType(String))})
dt.Rows.Add(1, "Mudassar Khan", "India")
dt.Rows.Add(2, "John Hammod", "USA")
dt.Rows.Add(3, "Robert Mathew", "France")
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub EmployeeCode_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim lnk As LinkButton = TryCast(sender, LinkButton)
Dim row As GridViewRow = CType(lnk.NamingContainer, GridViewRow)
Response.Redirect("Default.aspx?Id=" & lnk.CommandArgument & "&Name=" + row.Cells(1).Text)
End Sub
Default.aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
lblId.Text = "Id is : <b> " & Request.QueryString("Id") & "</b>"
lblName.Text = "Name is :<b> " & Request.QueryString("Name") & "</b>"
End Sub
Screenshot