473,320 Members | 1,974 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.

Bound DataGrid using nested XML

Hi,

I am trying to use a datagrid control to display hierarchical data in
a flat format essentially in a master-detail relationship. i.e.

<Data>
<Customer CustomerName="Customer1">
<Order OrderNumber="1">
<Item ItemName="Item1"></Item>
<Item ItemName="Item2"></Item>
</Order>
<Order OrderNumber="2">
<Item ItemName="Item3"></Item>
<Item ItemName="Item4"></Item>
</Order>
</Customer>
<Customer CustomerName="Customer2">
<Order OrderNumber="3">
<Item ItemName="Item1"></Item>
<Item ItemName="Item2"></Item>
</Order>
</Customer>
</Data>

When I load the xml data into the dataset, .NET creates the
relationships for me. My confusion happens when I bind this data to
my datagrid. I have set AutoGenerateColumns to false and manually
added each column. I can't seem to figure out how to set the
DataField for relational columns. i.e.

DataSet ds = new DataSet();
DataGrid dg = new DataGrid();
BoundColumn colCustomerName = new BoundColumn();
BoundColumn colOrderNumber = new BoundColumn();
BoundColumn colItemName = new BoundColumn();

ds.ReadXml("Data.xml", XmlReadMode.InferSchema);

colCustomerName.DataField =
ds.Tables["Customer"].Columns["CustomerName"].toString();
colOrderNumber.DataField =
ds.Tables["Order"].Columns["OrderNumber"].toString();
colItemName.DataField =
ds.Tables[Item].Columns["ItemName"].toString();

dg.DataSource = ds;
dg.DataBind();

I tried to build in the relationships by doing this a little bit
different, but this didn't seem to work either:

colCustomerName.DataField =
ds.Relations["Customer_Order"].ParentTable.Columns["CustomerName"].toString();
colOrderNumber.DataField =
ds.Relations["Order_Item"].ParentTable.Columns["OrderNumber"].toString();
colItemName.DataField = "ItemName";

dg.DataSource = ds;
dg.DataMember = "Item";
dg.DataBind();

How do I have to reference the DataSource and DataField properties to
display this relational data? I'd be especially grateful for any
assistance. Thanks.

-Chris
Nov 17 '05 #1
3 1288
Hi,

I think this link[1] will help you :

[1] - Displaying Hierarchical data with the ASP.NET Data Grid
: http://www.wimdows.net/articles/article.aspx?aid=19

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #2
Thanks.. I think the solution you offered will probably work for me.
What I had really hoped to accomplish in this particular project
though, was more of a "flat" display of the data using just a single
datagrid. i.e.

Customer Name | Order Number | Item Name
--------------------------------------------
Customer 1 | Order 1 | Item 1
Customer 1 | Order 1 | Item 2
Customer 1 | Order 2 | Item 3
Customer 1 | Order 2 | Item 4
Customer 2 | Order 3 | Item 1
Customer 2 | Order 3 | Item 2

Can this be done, or is it necessary to nest additional datagrids as
in your example?

-Chris

Natty Gur <na***@dao2com.com> wrote in message news:<O$**************@TK2MSFTNGP09.phx.gbl>...
Hi,

I think this link[1] will help you :

[1] - Displaying Hierarchical data with the ASP.NET Data Grid
: http://www.wimdows.net/articles/article.aspx?aid=19

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #3
Yes,

You can always create your own dataset with datatable that holds your
data (in certain format and form) and bind it to data grid.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Aaron Ackerman | last post by:
I am using typed datasets in an N-Tier Windows app using VB.NET. I know this posting cannot be fully explained in a single post that is why I am asking for someone to point me to a real world...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
3
by: Matthew Woods | last post by:
Hi, is there any way to format and order the columns displayed in a datagrid bound to a class that inherits from IBindingList? i have used DataGridTableStyle and added DataGridTextBoxColumns to it...
2
by: nulldevice | last post by:
I've got a datagrid with some nested controls, created at design-time. The controls themselves have no databound values. After a few other operations on the page (selecting a few parameters,...
0
by: Pat | last post by:
I have 3 Datagrid nested. Master Details Child The master has paging (And i'm using the paging inbuilt in the Datagrid) in the Master DataGrid you select a linkbutton(using commandname) and it...
0
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the...
1
by: needin4mation | last post by:
Hi, I have a datalist. In this datalist I have a datagrid. The datalist is the master. The datagrid is the detail. It works fine. I populate the datagrid inside of the datalist using the...
0
by: Marcus Kwok | last post by:
I am having a weird problem with my DataGrid that is bound to an ArrayList. My situation is as follows: I have two DataGrids on a modal form. The top grid populates an ArrayList from a file,...
0
by: TonyJ | last post by:
Hello! I'm unsure when I can use a bound datagrid and when I can't. What limitations has a bound datagrid? 1. For example if I want to manipulate the data in the datasource before displaying...
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
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.