473,320 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 3099
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: epigram | last post by:
I'm using the DataGrid with AutoGenerateColumns set to false and choosing which columns I want in the grid by using the <Columns> attribute. What I want to do is to create a hyperlink out of one...
3
by: Tim::.. | last post by:
I currently have the following datagrid but want to turn the name and email column into a hyperlink in the codebehind! Can someone please tell me how I achieve this! Thanks Private Sub...
0
by: Waran | last post by:
Hi, In a datagrid I am displaying 2 columns. One is a Hyperlink Colum and the other is a Button Column. The values for the hyperlink columns are fetched from the database and its a url. When I...
10
by: david | last post by:
Hi, all: I need a help from you about DataGrid control. I created a DataGrid, dg, in design view of .NET visual Stadio and use the builder to add a Hyperlink column to dg. I want to try to assign...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
1
by: serge calderara | last post by:
Dear all, I am building an ASP 1.1 applciation collecting data from an SQL server database. In one table field, users will have possibility to introduced a file path (attached document) What...
4
by: =?Utf-8?B?QW1pciBUb2hpZGk=?= | last post by:
Hi I have a GridView that is displaying master records. Some of these records have child records. I would like to a column to my master GridView such that for each master record that has...
3
by: Uriah Piddle | last post by:
Hi Gang, in VS 2005, I have an Asp:Hyperlink in a GridView TemplateField. I am trying to figure out how to make the text of the hyperlink wrap to the next line if it is too long. Setting the...
1
by: Valli | last post by:
Hi, I need to display an hyperlink column in gridview where if the user clicks that column the page should move to the selected page. I have got help from this group & started using template...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.