In this article I will explain with an example, how to send (pass) GridView Row Values to other Page using Session in ASP.Net using C# and VB.Net.
When the Send Button is clicked, the GridView Row values are saved in Session object and the values are sent (passed) to other Page in ASP.Net using C# and VB.Net.
 
 
HTML Markup
The HTML Markup consists of an ASP.Net GridView containing three BoundField columns and a TemplateField column.
The TemplateField columns consist of a Button which has been assigned an OnClick event handler.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="Id" HeaderText="Customer Id" ItemStyle-Width="80" />
        <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="120" />
        <asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="80" />
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Button Text="Send" runat="server" OnClick="Send" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
 
 
Namespaces
You will need to import the following namespace.
C#
using System.Data;
 
VB.Net
Imports System.Data
 
 
Binding the ASP.Net GridView control
Inside the Page Load event handler, the GridView is populated with a dynamic DataTable with some dummy data.
Note: You can learn more about this dynamic DataTable in my article Create DataTable dynamically and bind to GridView in ASP.Net.
 
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });
        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();
    }
}
 
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim dt As New DataTable()
        dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Id"), New DataColumn("Name"), New DataColumn("Country")})
        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()
    End If
End Sub
 
 
Sending (Passing) GridView Row Values to other Page using Session in ASP.Net
When the Send Button is clicked, first the Button is referenced and the GridView Row is referenced using it.
Then the GridView Row is saved in Session object and the Page is redirect.
C#
protected void Send(object sender, EventArgs e)
{
    //Reference the Button.
    Button btnSend = sender as Button;
 
    //Reference the GridView Row.
    GridViewRow row = btnSend.NamingContainer as GridViewRow;
 
    //Save the GridView Row in Session.
    Session["Row"] = row;
 
    //Redirect to other Page.
    Response.Redirect("Page2.aspx");
}
 
VB.Net
Protected Sub Send(ByVal sender As Object, ByVal e As EventArgs)
    'Reference the Button.
    Dim btnSend As Button = CType(sender, Button)
 
    'Reference the GridView Row.
    Dim row As GridViewRow = CType(btnSend.NamingContainer, GridViewRow)
 
    'Save the GridView Row in Session.
    Session("Row") = row
 
    'Redirect to other Page.
    Response.Redirect("Page2.aspx")
End Sub
 
 
Second Page HTML Markup
The second page HTML Markup consists of three Label controls for displaying the GridView Row values.
<table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td> Customer Id:</td>
        <td><asp:Label ID="lblCustomerId" runat="server" /></td>
    </tr>
    <tr>
        <td>Name:</td>
        <td><asp:Label ID="lblName" runat="server" /></td>
    </tr>
    <tr>
        <td>Country:</td>
        <td><asp:Label ID="lblCountry" runat="server" /></td>
    </tr>
</table>
 
 
Displaying GridView Row Values fetched from Session in ASP.Net
Inside the Page Load event handler, the GridView Row is referenced from the Session object and the Cell values are displayed in respective Label controls.
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        if (Session["Row"] != null)
        {
            //Fetch the GridView Row from Session.
            GridViewRow row = Session["Row"] as GridViewRow;
 
            //Fetch and display the Cell values.
            lblCustomerId.Text = row.Cells[0].Text;
            lblName.Text = row.Cells[1].Text;
            lblCountry.Text = row.Cells[2].Text;
        }
    }
}
 
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        If (Not (Session("Row")) Is Nothing) Then
 
            'Fetch the GridView Row from Session.
            Dim row As GridViewRow = CType(Session("Row"), GridViewRow)
 
            'Fetch and display the Cell values.
            lblCustomerId.Text = row.Cells(0).Text
            lblName.Text = row.Cells(1).Text
            lblCountry.Text = row.Cells(2).Text
        End If
    End If
End Sub
 
 
Screenshot
Send (Pass) GridView Row Values to other Page using Session in ASP.Net
 
 
Demo
 
 
Downloads