See in data source you have to provide select parameter with Session or QueryString when you are redirecting values from one page to another.
Here i am login to the websit redirecting to page2.aspx and i am binding the First GridView with Seesion and second with QueryString.
Login.aspx:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtId" runat="server" />
<asp:TextBox ID="txtPass" runat="server" />
<asp:Button ID="btnLigin" runat="server" Text="Save" />
</div>
</form>
Login: C#:
Protected Sub btnLigin_Click(sender As Object, e As System.EventArgs) Handles btnLigin.Click
Session("id") = Me.txtId.Text
Response.Redirect("Page2.aspx?id=" + Me.txtId.Text)
End Sub
Page2.aspx:
<form id="form1" runat="server">
<div>
Through Seesion
<asp:GridView ID="gvEmployees" runat="server" DataSourceID="sdsEmployees" AutoGenerateColumns="False"
DataKeyNames="EmployeeID">
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" InsertVisible="False"
ReadOnly="True" SortExpression="EmployeeID" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="TitleOfCourtesy" HeaderText="TitleOfCourtesy" SortExpression="TitleOfCourtesy" />
<asp:BoundField DataField="BirthDate" HeaderText="BirthDate" SortExpression="BirthDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sdsEmployees" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>"
SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [Title], [TitleOfCourtesy], [BirthDate] FROM [Employees] WHERE ([EmployeeID] = @EmployeeID)">
<SelectParameters>
<asp:SessionParameter DefaultValue="1" Name="EmployeeID" SessionField="Id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
Through QueryString
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
DataKeyNames="EmployeeID">
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" InsertVisible="False"
ReadOnly="True" SortExpression="EmployeeID" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="TitleOfCourtesy" HeaderText="TitleOfCourtesy" SortExpression="TitleOfCourtesy" />
<asp:BoundField DataField="BirthDate" HeaderText="BirthDate" SortExpression="BirthDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>"
SelectCommand="SELECT [EmployeeID], [FirstName], [LastName], [Title], [TitleOfCourtesy], [BirthDate] FROM [Employees] WHERE ([EmployeeID] = @EmployeeID)">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="1" Name="EmployeeID" QueryStringField="Id"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
For configuring SqlDataSource follow the steps:
1)Click on > (symbol) of SqlDataSource
2)Create the connection
3)Select Specify columns from table or view and select columns
4)Click on WHERE
5)Specify the column name to which you want to get the Data
6)Specify the Operator as =
7)Select Seesion or QueryString
8)set the Seesion or QueryStringField which you have defined in you code.
9)Click on Add and Test the connection.
Thank You.