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

来源:互联网 发布:达特茅斯学院知乎 编辑:程序博客网 时间:2024/05/22 12:20

 

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>