GridView:HyperLinkField不起作用

时间:2016-07-22 16:11:19

标签: asp.net xml vb.net gridview

我的问题是我无法弄清楚如何正确实现从xml工作表到GridView的链接。

我正在尝试使用表格来显示一组信息,包括姓名,网址和登录信息。这显示在下面的xml表中。我目前只是使用虚拟信息进行显示测试。

<?xml version="1.0" encoding="utf-8" ?>

<Sites xmlns:xlink="http://www.w3.org/1999/xlink">
  <Set_Info>
    <Name>Alpha</Name>
    <URL  >http://www.google.com</URL>
    <UserName>Blah</UserName>
    <Password>BlahBlah</Password>
  </Set_Info>
  <Set_Info>
    <Name>Beta</Name>
    <URL  >http://www.google.com</URL>
    <UserName>Blah</UserName>
    <Password>BlahBlah</Password>
  </Set_Info>
  <Set_Info>
    <Name>Gamma</Name>
    <URL >http://www.google.com</URL>
    <UserName>blah</UserName>
    <Password>blahblah</Password>
  </Set_Info>
</Sites>

我正在使用我的.aspx文件中声明的gridview:

<asp:GridView ID="GridView1" runat="server"   HeaderStyle-ForeColor="#FF5A09" RowStyle-ForeColor="#FF9900" 
        AutoGenerateColumns="false"  BorderWidth="2px" 
        Width="1294px" Height="267px"   >
 <Columns >
        <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150"  />
        <asp:BoundField DataField="URL" HeaderText="URL" ItemStyle-Width="400" />
        <asp:BoundField DataField="Username" HeaderText="Username" ItemStyle-Width="150" />
        <asp:BoundField DataField="Password" HeaderText="Password" ItemStyle-Width="150" />
    </Columns>

</asp:GridView>

在后面的代码中,我一直在绑定这样的数据:

        Dim ds As New DataSet
        ds.ReadXml(Server.MapPath("[path to my xml]"))
        GridView1.DataSource = ds
        GridView1.DataBind()

当我只是显示其工作的URL的文本时,但如果我想使文本作为像

这样的链接工作
<URL xlink:type="simple" xlink:href="http://www.google.com">http://www.google.com</URL>

并对gridview列进行相应的更改为

<asp:HyperLinkField DataField="URL" HeaderText="URL" ItemStyle-Width="400" />

每当我访问网站上显示的页面时,我都会崩溃。我已经搜索了其他解决方案,但找不到任何解决方案。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可以这样使用HyperLinkField:

<asp:HyperLinkField DataNavigateUrlFields="URL" DataNavigateUrlFormatString="{0}" DataTextField="URL" HeaderText="URL" ItemStyle-Width="400" />

它在XML数据中没有xlink属性。