Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Bound DataGrid using nested XML

Reply
Thread Tools

Bound DataGrid using nested XML

 
 
Christopher Jedlicka
Guest
Posts: n/a
 
      11-09-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lower bound & Upper bound sunil panda Java 9 10-07-2008 08:32 PM
dealing with nested xml within nested xml within...... Ultrus Python 3 07-09-2007 09:00 PM
How to represent the data in a not bound control via bound control Mario Krsnic ASP .Net 0 06-23-2006 07:38 AM
Getting lower-bound and upper-bound of strings input Rhiner Dan C++ 1 03-27-2005 02:03 AM
Bound DataGrid using nested XML Christopher Jedlicka ASP .Net 3 11-11-2003 07:23 AM



Advertisments