Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Hyperlink Column not displaying

 
Thread Tools Search this Thread
Old 09-18-2006, 05:03 AM   #1
Default 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()




William LaMartin
  Reply With Quote
Old 09-18-2006, 06:22 AM   #2
Martin CLAVREUIL
 
Posts: n/a
Default Re: Hyperlink Column not displaying
Why don't you do this in design mode ?

"William LaMartin" <> wrote in :
...
>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()
>





Martin CLAVREUIL
  Reply With Quote
Old 09-18-2006, 03:42 PM   #3
William LaMartin
 
Posts: n/a
Default Re: Hyperlink Column not displaying
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" <> wrote in message
news:%...
> Why don't you do this in design mode ?
>
> "William LaMartin" <> wrote in :
> ...
>>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()
>>

>
>





William LaMartin
  Reply With Quote
Old 09-18-2006, 09:49 PM   #4
William LaMartin
 
Posts: n/a
Default Re: Hyperlink Column not displaying
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" <> wrote in message
news:...
>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()
>





William LaMartin
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET: User Control Events is Not Displaying in a Property Window BabuA Software 0 09-14-2006 05:44 PM
hyperlink in asp.net saraswathyrajaram Software 0 08-22-2006 07:07 PM
DataGrid-Hyperlink column thiyag2001 Software 2 08-01-2006 12:50 PM
displaying a PC test machine? 6ftplus A+ Certification 4 10-15-2005 05:39 PM
Counting In Binary Raymond A+ Certification 13 03-07-2004 07:28 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46