We should set DataNavigateUrlFields and DataNavigateUrlFormatString
Properties of hyperlink in gridview to pass the row data
HTML markup of the page look like
Code:
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ID,Name,Location"
DataNavigateUrlFormatString=
"test.aspx?id={0}&name={1}&loc={2}"
Text="Transfer values to other page" />
<asp:BoundField DataField="ID" HeaderText="ID"
SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="Location" HeaderText="Location"
SortExpression="Location" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name], [Location] FROM [Details]">
</asp:SqlDataSource> Now write code mentioned below to get back values on test.aspx page
Code:
protected void Page_Load(object sender, EventArgs e)
{
string strID = Request.QueryString["id"];
string strName = Request.QueryString["name"];
string strLocation = Request.QueryString["loc"];
lblID.Text = strID;
lblName.Text = strName;
lblLocation.Text = strLocation;
}
Bookmarks