【问题标题】:GridView: how to Pass encoded data on click of hyperlink fieldGridView:如何在单击超链接字段时传递编码数据
【发布时间】:2012-02-06 18:42:52
【问题描述】:

当我尝试在 GridView 的超链接字段中传递编码的 URL 字符串时,如下所示:

<asp:HyperLinkField HeaderText="Customer" DataTextField="Customer" DataNavigateUrlFields="Customer"
    DataNavigateUrlFormatString= "Changes.aspx?customer={0}" SortExpression="Customer"
    NavigateUrl="~/Client.aspx" />

我收到此错误:

只有具有 DataBinding 事件的对象才支持数据绑定表达式。 System.Web.UI.WebControls.HyperLinkField 没有 DataBinding 事件

有什么方法可以在超链接字段中传递编码字符串?

替代方法:

另外,有什么方法可以读取查询字符串中的特殊字符?如果我使用它,我可以读到某个特定的特殊字符吗?

Request.QueryString["customer"]

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    这是从我在上面发布的 msdn 链接中截取的片段,它将向您展示您需要什么.. 遵循这个示例,它应该适合您.. 更改字段绑定值以匹配您的情况.. 从此链接粘贴的示例MSDN - HyperLinkField.DataNavigateUrlFormatString Property

     <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>
    

    【讨论】:

    • 感谢您的回复,但它没有将值作为编码值发送。
    • 我找到了解决方案。您需要将超链接字段转换为 Templete 字段,然后像我在下面传递的那样传递 navigationURL:NavigateUrl=''
    猜你喜欢
    • 2010-10-19
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 2012-02-20
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多