C# GridView:如何在单击超链接字段时传递编码数据
当我尝试在GridView的超链接字段中传递编码的URL字符串时,如下所示:C# GridView:如何在单击超链接字段时传递编码数据,c#,asp.net,gridview,C#,Asp.net,Gridview,当我尝试在GridView的超链接字段中传递编码的URL字符串时,如下所示: <asp:HyperLinkField HeaderText="Customer" DataTextField="Customer" DataNavigateUrlFields="Customer" DataNavigateUrlFormatString= "Changes.aspx?customer={0}" SortExpression="Customer" NavigateUrl="~/Cl
<asp:HyperLinkField HeaderText="Customer" DataTextField="Customer" DataNavigateUrlFields="Customer"
DataNavigateUrlFormatString= "Changes.aspx?customer={0}" SortExpression="Customer"
NavigateUrl="~/Client.aspx" />
下面是我在上面发布的msdn链接中的一个片段,它将向您展示您所需要的。。按照这个例子,它应该对你有用。。更改字段绑定值以匹配您的案例。。 从该链接粘贴的示例
HyperLinkField示例
感谢您的回复,但它不会将值作为编码值发送。我找到了解决方案。您需要将hyperlink字段转换为Templete字段,然后像我在下面传递一样传递navigationURL,如:NavigateUrl=''
Request.QueryString["customer"]
<h3>HyperLinkField Example</h3>
<!-- Populate the Columns collection declaratively. -->
<!-- The UnitPrice field values are bound to the -->
<!-- captions of the hyperlinks in the HyperLinkField -->
<!-- field column, formatted as currency. The ProductID -->
<!-- field values are bound to the navigate URLs of the -->
<!-- hyperlinks. However, instead of being the actual -->
<!-- URL values, the product ID is passed to the linked -->
<!-- page as a parameter in the URL specified by the -->
<!-- DataNavigateUrlFormatString property. -->
<asp:gridview id="OrdersGridView"
datasourceid="OrdersSqlDataSource"
autogeneratecolumns="false"
runat="server">
<columns>
<asp:boundfield datafield="OrderID"
headertext="Order ID"/>
<asp:boundfield datafield="ProductID"
headertext="Product ID"/>
<asp:hyperlinkfield datatextfield="UnitPrice"
datatextformatstring="{0:c}"
datanavigateurlfields="ProductID"
datanavigateurlformatstring="~\details.aspx?ProductID={0}"
headertext="Price"
target="_blank" />
<asp:boundfield datafield="Quantity"
headertext="Quantity"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. -->
<asp:sqldatasource id="OrdersSqlDataSource"
selectcommand="SELECT [OrderID], [ProductID], [UnitPrice], [Quantity] FROM [Order Details]"
connectionstring="server=localhost;database=northwind;integrated security=SSPI"
runat="server">
</asp:sqldatasource>