CSDN博客

img colayungnew

DataGrid超级链接列中绑定一个以上字段

发表于2004/12/30 11:10:00  1216人阅读

分类: ASP.NET

 

The DataGrid's HyperLinkColumn column is great to have a column with an hyperlink that points to an Url with a parameter whose value is taken from the data source, but what if you need to build the target Url with more than one parameter taken from the data source? In this case you can use a template column as follows:

<TemplateColumn>
    <ItemTemplate>
       <asp:HyperLink Runat="server" NavigateUrl='<%# "Details.aspx?EmployeeID=" & Container.DataItem("ID")&"&EmployeeName=" & Container.DataItem("FirstName")%>'/>
    </ItemTemplate>
</TemplateColumn>

Instead of doing the string concatenation yourself you can use the BuildUrlWithQueryString function, which must be declared with Public/Protected visibility in the code-behind, as follows:

<TemplateColumn>
    <ItemTemplate>
      <asp:HyperLink Runat="server" NavigateUrl='<%# _
         BuildUrlWithQueryString("Details.aspx", "EmployeeID", Container.DataItem("ID"),"EmployeeName", Container.DataItem("FirstName")) %>' />
   </ItemTemplate>
</TemplateColumn>

http://java.mblogger.cn/brian_jin/posts/2792.aspx

<asp:TemplateColumn HeaderText="购买">
<ItemTemplate>
<asp:HyperLink id=HyperLink1 runat="server"
 Text='<%# DataBinder.Eval(Container, "DataItem.dinggou")%>'
 NavigateUrl='<%# "../gouwu/gouwu_ls.aspx?commoditytype=" &
  DataBinder.Eval(Container, "DataItem.commoditytype")
  & "&commodityname=" & DataBinder.Eval(Container, "DataItem.commodityname")%>' />
</ItemTemplate>
</asp:TemplateColumn>

 


 

阅读全文
0 0

相关文章推荐

img
取 消
img