Thanks for trying. I guess I'm not skilled enough to make this work. I convert to VB and your code won't convert for me, and I don't use the console. I need to output to a webform via gridview, reapeater, table, anything.
Now here's a complete thing out for you, please put your codes inside the aspx page:
'Fetch all the columns
Dim columns = From item In doc.Descendants("column")item.Value
'Create a DataTable
Dim dt As New DataTable()
For Each item As var In columns
dt.Columns.Add(item)
Next
For Each item As var In doc.Descendants("row")
Dim dr As DataRow = dt.NewRow()
Dim results = item.Elements().ToArray()
For i As Integer = 0 To results.Length - 1
dr(i) = results(i).Value
Next
dt.Rows.Add(dr)
Next
GridView1.DataSource = dt
GridView1.DataBind()
jcmartin
Member
2 Points
27 Posts
xml with column and cell names to gridview or table
Jan 02, 2013 03:54 PM|LINK
My apologies if the answer to this question appears elsewhere in this forum. I have been searching for days and I am stumped.
We have a rest request from a client API that we cannot parse. The XML structure is
What we want to output to a web form is:
Date
Clicks
Conversions
impressions
Etc
2012/12/24
24
2
802
Etc
2012/12/25
23
0
704
Etc
The <columns> will change based on the http request, so we have to populate the header row dynamically.
Thanks in advance, I feel that there is a simple answer that is eluding us.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: xml with column and cell names to gridview or table
Jan 03, 2013 04:19 AM|LINK
Hello:
1) You can fetch all the columns name.
2) and then fetch each value from the <row> and then do calculation:
Now here's an example:
jcmartin
Member
2 Points
27 Posts
Re: xml with column and cell names to gridview or table
Jan 03, 2013 01:11 PM|LINK
Thanks, but I can't make this work. I keep getting all my data in one cell like:
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: xml with column and cell names to gridview or table
Jan 04, 2013 12:56 AM|LINK
sorry please have a try like this:
jcmartin
Member
2 Points
27 Posts
Re: xml with column and cell names to gridview or table
Jan 04, 2013 04:35 PM|LINK
Thanks for trying. I guess I'm not skilled enough to make this work. I convert to VB and your code won't convert for me, and I don't use the console. I need to output to a webform via gridview, reapeater, table, anything.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: xml with column and cell names to gridview or table
Jan 05, 2013 02:37 AM|LINK
Hi again,
Now here's a complete thing out for you, please put your codes inside the aspx page:
'Fetch all the columns Dim columns = From item In doc.Descendants("column")item.Value 'Create a DataTable Dim dt As New DataTable() For Each item As var In columns dt.Columns.Add(item) Next For Each item As var In doc.Descendants("row") Dim dr As DataRow = dt.NewRow() Dim results = item.Elements().ToArray() For i As Integer = 0 To results.Length - 1 dr(i) = results(i).Value Next dt.Rows.Add(dr) Next GridView1.DataSource = dt GridView1.DataBind()jcmartin
Member
2 Points
27 Posts
Re: xml with column and cell names to gridview or table
Jan 05, 2013 12:21 PM|LINK
Compiler Error Message: BC30205: End of statement expected.
Source Error:
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: xml with column and cell names to gridview or table
Jan 06, 2013 02:25 AM|LINK
Hi,
You can just use:
Dim columns = From item In doc.Descendants("column") Select item.Value
jcmartin
Member
2 Points
27 Posts
Re: xml with column and cell names to gridview or table
Jan 06, 2013 12:45 PM|LINK
Sucess, thanks!
Changed
For Each item As var In columns
...
For Each item As var In doc.Descendants("row")
to
For Each item In columns
...
For Each item In doc.Descendants("row")