66Mhz
66Mhz

Reputation: 225

Retrieving a URL parameter and passing it into a HyperLinkField inside GridView

I'm trying to retrieve a URL parameter and pass it into a HyperLinkField inside my GridView.

The URL looks like http://application.com/dynamic.aspx?locale=us. I need to pull the value of the locale param and include it in the asp:HyperLinkField. I know that I can retrieve this param in the code behind like this:

Request.QueryString["locale"].ToString()

But is it possible to retrieve this value inside the .aspx?

<asp:HyperLinkField DataTextField="ref_id" DataNavigateUrlFields="???,ref_id" DataNavigateUrlFormatString="dynamic.aspx?locale={0}&id={1}" Text="ID" HeaderText="ID" SortExpression="ref_id" >

Upvotes: 0

Views: 253

Answers (1)

VDWWD
VDWWD

Reputation: 35514

Better switch to a TemplateField. You have much more control that way.

<asp:TemplateField HeaderText="ID">
   <ItemTemplate>
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# string.Format("/dynamic.aspx?locale={0}&id={1}", Request.QueryString["locale"], Eval("ref_id")) %>'><%# Eval("ref_id") %></asp:HyperLink>
    </ItemTemplate>
</asp:TemplateField>

Upvotes: 1

Related Questions