470,568 Members | 1,535 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,568 developers. It's quick & easy.

Hyperlink Column not displaying

I have a gridview (with no properties set) on an aspx page which I populate
from an XML file with the code below.

The data in the XML file looks like this

<description>National Trust for Historic Preservation</description>
<URL>http://www.nthp.org/</URL>
<category>Architecture</category>

Can anyone tell me why the other two columns are displayed, but the
hyperlink column does not display in the grid?

The code:

Dim DS As New Data.DataSet
DS.ReadXml(Server.MapPath(".") & "\data\Links.xml")
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
Dim hl As New HyperLink
Dim i As Integer

dt.Columns.Add(New Data.DataColumn("Description", GetType(String)))
dt.Columns.Add(New Data.DataColumn("URL", GetType(HyperLink)))
dt.Columns.Add(New Data.DataColumn("Category", GetType(String)))

For i = 0 To DS.Tables(0).Rows.Count - 1

dr = dt.NewRow
dr("Description") = DS.Tables(0).Rows.Item(i).Item(0) 'The link's
description
hl.NavigateUrl = DS.Tables(0).Rows.Item(i).Item(1) 'the link's URL
hl.Text = DS.Tables(0).Rows.Item(i).Item(0) 'description
hl.Target = "_Blank"
dr("URL") = hl
dr("Category") = DS.Tables(0).Rows.Item(i).Item(2) 'The link's category
dt.Rows.Add(dr)
Next

Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
Sep 18 '06 #1
3 2981
Why don't you do this in design mode ?

"William LaMartin" <la******@tampabay.rr.comwrote in :
Og**************@TK2MSFTNGP03.phx.gbl...
>I have a gridview (with no properties set) on an aspx page which I populate
from an XML file with the code below.

The data in the XML file looks like this

<description>National Trust for Historic Preservation</description>
<URL>http://www.nthp.org/</URL>
<category>Architecture</category>

Can anyone tell me why the other two columns are displayed, but the
hyperlink column does not display in the grid?

The code:

Dim DS As New Data.DataSet
DS.ReadXml(Server.MapPath(".") & "\data\Links.xml")
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
Dim hl As New HyperLink
Dim i As Integer

dt.Columns.Add(New Data.DataColumn("Description", GetType(String)))
dt.Columns.Add(New Data.DataColumn("URL", GetType(HyperLink)))
dt.Columns.Add(New Data.DataColumn("Category", GetType(String)))

For i = 0 To DS.Tables(0).Rows.Count - 1

dr = dt.NewRow
dr("Description") = DS.Tables(0).Rows.Item(i).Item(0) 'The link's
description
hl.NavigateUrl = DS.Tables(0).Rows.Item(i).Item(1) 'the link's URL
hl.Text = DS.Tables(0).Rows.Item(i).Item(0) 'description
hl.Target = "_Blank"
dr("URL") = hl
dr("Category") = DS.Tables(0).Rows.Item(i).Item(2) 'The link's category
dt.Rows.Add(dr)
Next

Me.GridView1.DataSource = dt
Me.GridView1.DataBind()

Sep 18 '06 #2
Because for some reason when I try to add my XML file as an XMLDataSource in
design mode I receive the following message:

There was an error rendering the control.
The data source for GridView with id 'GridView1' did not have any properties
or attributes from which to generate columns. Ensure that your data source
has content.

In researching this, I have read that instead of the structure my XML file
has, what is wanted is for each item to have attributes instead of elements.
I haven't looked into doing this, though.

Furthermore, I have found it more flexible to generate data connections in
code. And I am sure there is a way to get the hyperlink column to display
this way--I just haven't found it.
"Martin CLAVREUIL" <az****@azerty.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Why don't you do this in design mode ?

"William LaMartin" <la******@tampabay.rr.comwrote in :
Og**************@TK2MSFTNGP03.phx.gbl...
>>I have a gridview (with no properties set) on an aspx page which I
populate from an XML file with the code below.

The data in the XML file looks like this

<description>National Trust for Historic Preservation</description>
<URL>http://www.nthp.org/</URL>
<category>Architecture</category>

Can anyone tell me why the other two columns are displayed, but the
hyperlink column does not display in the grid?

The code:

Dim DS As New Data.DataSet
DS.ReadXml(Server.MapPath(".") & "\data\Links.xml")
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
Dim hl As New HyperLink
Dim i As Integer

dt.Columns.Add(New Data.DataColumn("Description", GetType(String)))
dt.Columns.Add(New Data.DataColumn("URL", GetType(HyperLink)))
dt.Columns.Add(New Data.DataColumn("Category", GetType(String)))

For i = 0 To DS.Tables(0).Rows.Count - 1

dr = dt.NewRow
dr("Description") = DS.Tables(0).Rows.Item(i).Item(0) 'The link's
description
hl.NavigateUrl = DS.Tables(0).Rows.Item(i).Item(1) 'the link's URL
hl.Text = DS.Tables(0).Rows.Item(i).Item(0) 'description
hl.Target = "_Blank"
dr("URL") = hl
dr("Category") = DS.Tables(0).Rows.Item(i).Item(2) 'The link's category
dt.Rows.Add(dr)
Next

Me.GridView1.DataSource = dt
Me.GridView1.DataBind()


Sep 18 '06 #3
The solution was to do a little hand coding on the source page of the aspx
file containing the GridView as below to create the hyperlink column. Then
create a dataset from the XML file as a datasource for the GridView and
importantly set AutoGenerateColumns=False to keep from getting redundant
data. (The field names in the XML file are and dataset are description, URL
and Category)

<asp:GridView ID="GridView1" runat="server" Style="z-index: 100; left: 17px;
position: absolute;
top: 82px">

<Columns>
<asp:HyperLinkField
HeaderText="Site"
DataTextField="description"
DataTextFormatString="{0}"
DataNavigateUrlFields="URL"
DataNavigateUrlFormatString="{0}"
Target="_Blank"
/>
<asp:BoundField DataField="Category" HeaderText="Category">
</Columns>
</asp:GridView>
"William LaMartin" <la******@tampabay.rr.comwrote in message
news:Og**************@TK2MSFTNGP03.phx.gbl...
>I have a gridview (with no properties set) on an aspx page which I populate
from an XML file with the code below.

The data in the XML file looks like this

<description>National Trust for Historic Preservation</description>
<URL>http://www.nthp.org/</URL>
<category>Architecture</category>

Can anyone tell me why the other two columns are displayed, but the
hyperlink column does not display in the grid?

The code:

Dim DS As New Data.DataSet
DS.ReadXml(Server.MapPath(".") & "\data\Links.xml")
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
Dim hl As New HyperLink
Dim i As Integer

dt.Columns.Add(New Data.DataColumn("Description", GetType(String)))
dt.Columns.Add(New Data.DataColumn("URL", GetType(HyperLink)))
dt.Columns.Add(New Data.DataColumn("Category", GetType(String)))

For i = 0 To DS.Tables(0).Rows.Count - 1

dr = dt.NewRow
dr("Description") = DS.Tables(0).Rows.Item(i).Item(0) 'The link's
description
hl.NavigateUrl = DS.Tables(0).Rows.Item(i).Item(1) 'the link's URL
hl.Text = DS.Tables(0).Rows.Item(i).Item(0) 'description
hl.Target = "_Blank"
dr("URL") = hl
dr("Category") = DS.Tables(0).Rows.Item(i).Item(2) 'The link's category
dt.Rows.Add(dr)
Next

Me.GridView1.DataSource = dt
Me.GridView1.DataBind()

Sep 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by epigram | last post: by
3 posts views Thread by Tim::.. | last post: by
3 posts views Thread by TPhelps | last post: by
1 post views Thread by serge calderara | last post: by
4 posts views Thread by =?Utf-8?B?QW1pciBUb2hpZGk=?= | last post: by
3 posts views Thread by Uriah Piddle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.