MacedonZero MacedonZero - 3 months ago 13 Question

GridView: HyperLinkField does not work

My problem is that I can't figure out how to correctly implement links from an xml sheet into a GridView.

I'm trying to use a table to show a set of information, including name, url, and sign in info. This is shown in the below xml sheet. I am currently just using dummy information for display testing.

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

<Sites xmlns:xlink="">
<URL ></URL>
<URL ></URL>
<URL ></URL>

I am using a gridview declared thusly in my .aspx file:

<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" />


In the code behind, I had been binding the data like this:

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

When I was just displaying the text for the URL it worked, but if I want to make the text work as a link like

<URL xlink:type="simple" xlink:href=""></URL>

and make the corresponding change to gridview column to

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

Then I crash whenever I visit the page on the website this appears on. I've searched for other solutions but can't find any. Any help would be greatly appreciated.


You can use the HyperLinkField this way:

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

It works without the xlink attribute in the XML data.