2012-02-06 62 views
0

的點擊編碼數據。當我試圖在GridView中的超鏈接字段通過編碼的URL字符串象下面這樣:GridView控件:如何通過超鏈接場

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

我得到這個錯誤:

Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.HyperLinkField does not have a DataBinding event

有沒有什麼辦法可以在超鏈接字段中傳遞編碼的字符串?

另一種方法:

另外,有沒有什麼辦法,我們可以在查詢字符串中讀取特殊字符?如果我使用這個功能,我可以閱讀一些特定的特殊字符嗎?

Request.QueryString["customer"] 

回答

0

下面是從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> 
+0

感謝您的答覆,但它不發送值作爲編碼值。 – 2012-02-06 19:57:23

+0

我找到了解決方案。您需要將超鏈接字段轉換爲Templete字段,然後傳遞navigationURL,如下所示:NavigateUrl ='<%#Eval(「Customer」,「Clients.aspx?customer =」+ Server.UrlEncode(Eval(「Customer 「).ToString()))%>' – 2012-02-06 20:02:51

+0

很酷..是MSDN網站不適合你的例子..只是好奇.. – MethodMan 2012-02-06 20:05:27