473,669 Members | 2,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="C ustomer1">
<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="C ustomer2">
<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 AutoGenerateCol umns 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("Dat a.xml", XmlReadMode.Inf erSchema);

colCustomerName .DataField =
ds.Tables["Customer"].Columns["CustomerNa me"].toString();
colOrderNumber. DataField =
ds.Tables["Order"].Columns["OrderNumbe r"].toString();
colItemName.Dat aField =
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.Co lumns["CustomerNa me"].toString();
colOrderNumber. DataField =
ds.Relations["Order_Item "].ParentTable.Co lumns["OrderNumbe r"].toString();
colItemName.Dat aField = "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 1315
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$******* *******@TK2MSFT NGP09.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
3568
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 tutorial (in vb.net) that can show me how to use a bound Datagrid to it's fullest potential. I need to utilize the bound Datagrid in two modes. One were a bound Datagrid can be in edited directly utilizing bound combos and textbox right on the grid,...
2
945
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 datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
3
1788
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 in the correct order which works fine if the dataGrid.dataSource = "ArrayList", but it doesn't work for my IBindingList wrapper. If i bind the datasource to the arraylist method then the ListChangedEventHandler is never invoked and my grid only...
2
1691
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, etc), a button is clicked and the databind occurs. This part works fine. It retreives the 4-10 rows it needs and using the itemdatabound formats everything nicely. What I intend to do then, is after the user has gone through the nested controls...
0
1340
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 populates the data in the Details DataGrid (I'm using Dim Filter As String = CStr(dtgMaster.DataKeys(dtgMaster.SelectedIndex)).Replace("'", "''") to filter btw the Datagrids)
0
1695
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 OnEditCommand event is raised, I try to do the following: 1. Find the selected datalist item in which the nested datagrid raised the event. (by calling getDataGridReference and returning the DataList's selectedIndex)
1
2564
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 datalist's itemdatabound event. Now I need to do some work in the itemdatabound event of the datagrid that is nested. I can't seem to reference it. How can I reference it so that they page knows to look for that event? How can I get to the...
0
1254
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, then the datagrid is bound to it, and it works fine. The bottom DataGrid is bound to a different ArrayList that holds the same type as the first ArrayList. Both DataGrids are set to Read-Only. The user selects a row from the top DataGrid, then...
0
1234
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 the data in the datagrid can I then use a bound datagrid? 2. For example if I only want to display some of the columns of a datasource table can I then use a bound datagrid? 3. For example if I some of the columns in a datagrid should be readonly...
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.