![]() |
|
|
|||||||
![]() |
ASP Net - Hyperlink Column not displaying |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
|
|
#4 |
|
Posts: n/a
|
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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |