检索 URL 参数并将其传递到 GridView 中的 HyperLinkField
Retrieving a URL parameter and passing it into a HyperLinkField inside GridView
我正在尝试检索 URL 参数并将其传递到我的 GridView 中的 HyperLinkField。
URL 看起来像 http://application.com/dynamic.aspx?locale=us。我需要提取 locale 参数的值并将其包含在 asp:HyperLinkField 中。我知道我可以像这样在后面的代码中检索这个参数:
Request.QueryString["locale"].ToString()
但是是否可以在 .aspx 中检索此值?
<asp:HyperLinkField DataTextField="ref_id" DataNavigateUrlFields="???,ref_id" DataNavigateUrlFormatString="dynamic.aspx?locale={0}&id={1}" Text="ID" HeaderText="ID" SortExpression="ref_id" >
最好切换到 TemplateField。这样你就拥有了更多的控制权。
<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>
我正在尝试检索 URL 参数并将其传递到我的 GridView 中的 HyperLinkField。
URL 看起来像 http://application.com/dynamic.aspx?locale=us。我需要提取 locale 参数的值并将其包含在 asp:HyperLinkField 中。我知道我可以像这样在后面的代码中检索这个参数:
Request.QueryString["locale"].ToString()
但是是否可以在 .aspx 中检索此值?
<asp:HyperLinkField DataTextField="ref_id" DataNavigateUrlFields="???,ref_id" DataNavigateUrlFormatString="dynamic.aspx?locale={0}&id={1}" Text="ID" HeaderText="ID" SortExpression="ref_id" >
最好切换到 TemplateField。这样你就拥有了更多的控制权。
<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>