473,785 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URGENT: Multidimensiona l hierarchical XML in TreeView

Hello!

I have an urgent problem concerning ASP.NET, ADO.NET, SQL Server, XML and
the TreeView control.
I have two tables; one describing the products and one describing their
relationships. A product may consist of multiple other products. So far
everything is great. But one product may exist as a subproduct to multiple
parent products.

My tables:
Products(prod_i d, nam)
ProductRelation (prod_id, parent_id)

My relation:
Product 1 consists of Product 2 and Product 3.
Product 4 consists of Product 5 AND Product 3.

My data in the table ProductRelation :
product 2, product 1
product 3, product 1
product 5, product 4
product 3, product 4 // This is what causes the error; product 3.

My intentions:
Retrieving the data from a MS SQL Server 7 and transforming it into XML, a
TreeView control is to be used to display the hierarchical data. The problem
is that I don't know how to make this work. Storing it and retrieving it is
of no problem, but the fact that product 3 is nested in two different places
makes it a bit hard.
Think of it as a manufacturer who makes different products as tables and
chairs and nails. Nails are used in both tables and chairs...

My code:
//DataSet
DataSet ds = new DataSet("COMPON ENTDS");

//Fill DataSet
da.Fill(ds, "COMPONENT" );

// Create a recursive data relation.
DataColumn col1 = ds.Tables[0].Columns["prod_id"];
DataColumn col2 = ds.Tables[0].Columns["parent_id"];
DataRelation drel = new DataRelation("P RODUCTS_RECURSI VE", col1, col2,
true);
drel.Nested = true;
ds.Relations.Ad d(drel);

//XmlDocument to hold XML generated from DataSet
XmlDocument objDoc = new XmlDocument();

//Load XML
objDoc.LoadXml( ds.GetXml());

//Create XslTransform object
XslTransform objXSL = new XslTransform();

//Load XSLT stylesheet
objXSL.Load(Ser ver.MapPath("hi erarchy.xslt")) ;

//StringWriter to temporarily hold result of the transformation
StringWriter writer = new StringWriter();

//Apply transformation with no arguments and dump results to StringWriter.
objXSL.Transfor m(objDoc.Create Navigator(),nul l,writer);

//Set TreeView's TreeNodeSrc property to get XML from StringWriter.
// tvTest2 is the TreeView control.
tvTest2.TreeNod eSrc = writer.ToString ();

//Bind TreeView
tvTest2.DataBin d();

//Close StringWriter
writer.Close();
Some notes:
This code works fine if I don't insist on having a product as a sub product
to multiple products. The drel.Nested = true makes it so easy. (: However,
this won't work like I want it. I've tried setting ds.EnforceConst raints =
false, but that only throws an error when trying the ds.GetXml().
I found the methodology at this URL:
http://aspalliance.com/joteke/treevi...e/article.aspx

Can anyone help me with this problem?
How do I EASILY get this kind of multidimensiona l parent-child relationship
converted to hierarchical XML so that the TreeView control can display it?

- Björn
Nov 17 '05 #1
0 1779

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

Similar topics

1
1799
by: jayson_13 | last post by:
Hi, I want to retrieve the hierarchical structure which is store inside the database and then display it using treeview control. But now I got a design issue which I hope that you guys can help me. My hierarchical structure has five levels which is store in table call level1, level2,… level5. Each level remember the parent ID e.g. level5 contains a column called level4ID. How should I implement it in order to get fastest loading?...
4
3403
by: Gönen EREN | last post by:
how can i collapse or expand a node of treeview control programmaticly? thanks.
1
1870
by: Neil McGuigan | last post by:
Hi, I want to store product categories in my db and am a little lost as to where to start. They can be hierarchical, such as "Books" > "Cook Books", so my table is like this: int CategoryId int ParentCategoryId Nullable
3
2044
by: Bennett Haselton | last post by:
I want to display a hierarchical listing of items from a database table, where, say, each row in the table has an "ID" field and a "parent_id" field giving the ID of its parent (NULL if it's at the top level of the hierarchy) -- like message posts and their replies. Is there a built-in way to do this, or a generally accepted simplest way? My first idea was to create a user control like HierarchicalListing that contains a Repeater, and...
2
5865
by: Don | last post by:
In a previous version of vb I used to save and load hierarchical data from an Access db into a treeview. But, I never found a very satisfying or elegant way to do it. I used a flat file approach with each item having a reference to its parent node. I would then start by loading the top level nodes folowed by loading child node data only as their parent node was expanded. This method worked fairly well except that allowing the user to...
2
1542
by: Olav | last post by:
I need a control to display a hierarchical tree of data and each node in the tree should have a checbox to select / unselect that part of the tree. Selecting / unselecting a top node should select / unselect all the children. What kind of control is best fit for this? Any samples? Olav
0
1289
by: Adam Right | last post by:
Hi ! I have a hierarchical field (from database with a DataReader) , every 3 digit must stand for a node in a TreeView item for windows application Sample collocation is ... ------------------------------------------- 000 --root 000000 --roots first node 000000000 --child of roots first node 000001 --roots second node
1
4165
by: selvakumari | last post by:
Hi, i am new to C#, i have a multiselection treeview, where if i select a nodes with ctrl and shift corresponding nodes will be copied to another treenode, i want to unselect the childnode selection with ctrl and shift if parent node is selected. i think of disablin the mouse click event inside that treenode if parent node is selected?
4
4383
by: Marco Pais | last post by:
Hi there. I am trying to find th best way (best UI control) to present hierarchical data, nested tables. For example, I have a Employees table (id, name) and EmployeesSales (id, idEmp, description, value). I want to show this in an hierarchical mode, so I tried DataGrid control. However, as I read somewhere, this DataGrid can only show one table at a time, i.e., when I click "plus" sign, I have only a link to the EmployeesSales table.
0
9645
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
9480
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
10325
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...
1
10091
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
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.