GridView:如何在点击超链接字段时传递编码数据
本文关键字:字段 数据 编码 超链接 GridView | 更新日期: 2023-09-27 18:23:46
当我试图在GridView的超链接字段中传递编码的URL字符串时,如下所示:
<asp:HyperLinkField HeaderText="Customer" DataTextField="Customer" DataNavigateUrlFields="Customer"
DataNavigateUrlFormatString= "Changes.aspx?customer={0}" SortExpression="Customer"
NavigateUrl="~/Client.aspx" />
我得到这个错误:
只有具有Databinding事件的对象才支持Databinding表达式。System.Web.UI.WebControls.HyperLinkField没有DataBinding事件
有什么方法可以在超链接字段中传递编码字符串吗?
替代方法:
此外,有没有什么方法可以读取查询字符串中的特殊字符?如果我使用这个,我可以一直读到一些特定的特殊字符吗?
Request.QueryString["customer"]
这是我在上面发布的msdn链接中的一个片段,它将向您展示您的需求。。按照这个例子,它应该对你有用。。更改字段绑定值以匹配您的情况。。从该链接粘贴的示例MSDN-HyperLinkField.DataNavigateUrlFormatString属性
<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>