I had success loading a simplified xml file into a gridview using this:
<?xml version="1.0" encoding="utf-8" ?>
<Employee>
<em>
<id>1</id>
<name>Guild</name>
<phone>123</phone>
</em>
<em>
<id>2</id>
<name>Gibson</name>
<phone>234</phone>
</em>
<em>
<id>3</id>
<name>Martin</name>
<phone>567</phone>
</em>
<em>
<id>4</id>
<name>Fender</name>
<phone>890</phone>
</em>
</Employee>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim oDs As New DataSet
oDs.ReadXml(Request.PhysicalApplicationPath + "XMLFile3.xml")
GridView1.DataSource = oDs
GridView1.DataBind()
End Sub
Now I need to try and do it for real with this file: (see below), But as you see the file is formated differently. How can I load this information into a gridview? The file also has two levels: A total record leading off and then the sub detail records.
As you said, you want to display data in different hierarchical levels, am I right? I run the code with both files and I can load both in a grid view, but, of course, without any hierarchical representation of rows and subrows as you like to do. The Gridview
control only display tables or queries without hierarchical representation of rows and subrows: I include a couple of links bellow where some information is found about gridviews displaying different hierarchical levels of data and how to implement them or
use them.
StrangerMike
Contributor
2710 Points
1757 Posts
Trying to load an xml file into a gridview
Jan 09, 2013 03:41 PM|LINK
Very new at this.
I had success loading a simplified xml file into a gridview using this:
<?xml version="1.0" encoding="utf-8" ?> <Employee> <em> <id>1</id> <name>Guild</name> <phone>123</phone> </em> <em> <id>2</id> <name>Gibson</name> <phone>234</phone> </em> <em> <id>3</id> <name>Martin</name> <phone>567</phone> </em> <em> <id>4</id> <name>Fender</name> <phone>890</phone> </em> </Employee> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim oDs As New DataSet oDs.ReadXml(Request.PhysicalApplicationPath + "XMLFile3.xml") GridView1.DataSource = oDs GridView1.DataBind() End SubNow I need to try and do it for real with this file: (see below), But as you see the file is formated differently. How can I load this information into a gridview? The file also has two levels: A total record leading off and then the sub detail records.
<?xml version="1.0" encoding="utf-8" ?> <xmlfile> <DataRow name="2012-12 - 2013-01"> <list name="attributes"/>-<list name="measures"> <float name="Visits">1275675</float> <float name="Page Views">3992199</float> <float name="Single Page View Visits">582306</float> <float name="Entry Page Visits">1275120</float> <float name="Avg Visit Duration (Min)">3.1446085928030261</float> <float name="Views per Visit">3.1294796872244106</float> <float name="Bounce Rate">45.666760775456424</float> </list>-<list name="SubRows"> -<list name="SubRows"> -<DataRow name="Returning Visitors"> <list name="attributes"/>-<list name="measures"> <float name="Visits">747621.00</float> <float name="Page Views">2732743.00</float> <float name="Single Page View Visits">252133.00</float> <float name="Entry Page Visits">747083.00</float> <float name="Avg Visit Duration (Min)">4.00</float> <float name="Views per Visit">3.66</float> <float name="Bounce Rate">33.75</float> </list> </DataRow>-<DataRow name="New Visitors"> <list name="attributes"/>-<list name="measures"> <float name="Visits">485449.00</float> <float name="Page Views">1146468.00</float> <float name="Single Page View Visits">308705.00</float> <float name="Entry Page Visits">485449.00</float> <float name="Avg Visit Duration (Min)">1.89</float> <float name="Views per Visit">2.36</float> <float name="Bounce Rate">63.59</float> </list> </DataRow>-<DataRow name="Visitors Not Accepting Cookies"> <list name="attributes"/>-<list name="measures"> <float name="Visits">42605.00</float> <float name="Page Views">112988.00</float> <float name="Single Page View Visits">21468.00</float> <float name="Entry Page Visits">42588.00</float> <float name="Avg Visit Duration (Min)">2.49</float> <float name="Views per Visit">2.65</float> <float name="Bounce Rate">50.41</float> </list> </DataRow> </list> </list> </DataRow> </xmlfile>otnielpena
Member
210 Points
38 Posts
Re: Trying to load an xml file into a gridview
Jan 11, 2013 12:02 AM|LINK
As you said, you want to display data in different hierarchical levels, am I right? I run the code with both files and I can load both in a grid view, but, of course, without any hierarchical representation of rows and subrows as you like to do. The Gridview control only display tables or queries without hierarchical representation of rows and subrows: I include a couple of links bellow where some information is found about gridviews displaying different hierarchical levels of data and how to implement them or use them.
http://aspalliance.com/articleViewer.aspx?aId=21
http://msdn.microsoft.com/en-us/magazine/cc164077.aspx
http://www.dotnetjunkies.com/Tutorial/841522C9-FFBD-4C57-BD48-F62B55057FF3.dcik
kavita_khand...
Star
9767 Points
1931 Posts
Re: Trying to load an xml file into a gridview
Jan 12, 2013 06:27 AM|LINK
If you want hierarchical representation of your xml, then I suggest you should go with Repeaters instead of GridView.
I would love to change the world, but they wont give me the source code.