2012-12-25 37 views
-2

我在SQL Server中有一個表,列X,Y,Z 我已經在ASP.Net的gridview中檢索到。如何在asp .net網格視圖中製作超鏈接

現在我想要第一個字段(例如X)作爲超鏈接,因爲我點擊打開一個新頁面。我怎麼用代碼來做到這一點?

+0

你試過什麼嗎? –

回答

1

將一個HyperLinkField添加到gridview並將其DataNavigateUrlFields屬性設置爲「X」和目標屬性設置爲「_blank」。

0
<Columns> 
<!-- first column--> 
<asp:TemplateField> 
    <ItemTemplate> 
     <asp:HyperLink runat="server" NavigateUrl='<%# string.Format("~/Details.aspx?Id={0}&Name={1}&Country={2}", 
      HttpUtility.UrlEncode(Eval("Id").ToString()), HttpUtility.UrlEncode(Eval("Name").ToString()), HttpUtility.UrlEncode(Eval("Country").ToString())) %>' 
      Text="View Details" /> 
    </ItemTemplate> 
</asp:TemplateField> 


<!-- second column--> 
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />  

<!-- third column--> 
<asp:BoundField DataField="Town" HeaderText="Country" ItemStyle-Width="150" /> 

<!-- fourth column as hyperlink --> 
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" /> 
</Columns>