GridView HyperLink field in C#
Use the DataNavigateUrlFields
property, comma-delimited value with the fields for parameters in "KeywordSrchSumDtl.aspx?Keyword={0}&State={1}&City={2}"
<asp:HyperLinkField DataNavigateUrlFields="Keyword,State,City"
DataNavigateUrlFormatString="KeywordSrchSumDtl.aspx?Keyword={0}&State={1}&City={2}"
Text="View Details" />
A couple of examples:
Passing two arguments in DataNavigateUrlFormatString in hyperlink field of .NET 2.0 Grid-View
Pass Multiple Values from a GridView to Another Page using ASP.NET
EDIT:
Set NavigateUrl
of HyperLink in RowDataBound
event of GridView
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="Keyword"
DataSourceID="SqlDataSource1"
onrowdatabound="GridView1_RowDataBound">
<asp:TemplateField HeaderText="Keyword" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:HyperLink ID="link" runat="server" Text='<%# Eval("Keyword") %>' />
</ItemTemplate>
</asp:TemplateField>
.......
</asp:GridView>
Code behind:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink hl = (HyperLink)e.Row.FindControl("link");
if (hl != null)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
string keyword = drv["Keyword"].ToString();
string state = Request.QueryString["State"];
string city = Request.QueryString["City"];
hl.NavigateUrl = "~/KeywordSrchSumDtl.aspx?Keyword=" + keyword + "&State=" + Server.UrlEncode(state) + "&City=" + Server.UrlEncode(city);
}
}
}