Extended TreeView
page 5 of 10
by G. Mohyuddin
Feedback
Average Rating: 
Views (Total / Last 10 Days): 44758/ 80

Binding with Database

Generally, binding a TreeView with database requires much to do with code. It requires opening connection, populating a dataset with all required tables and establishing the relationship between them. XTreeView minimizes this effort by providing you few properties to bind it with database directly. Before mentioning these properties, I would like to explain shortly the necessary information ASP.NET TreeView requires for binding with database. 

Generally binding a TreeView with database requires the following steps.                            

Open Connection

Populate Dataset with the parent table.

Populate Dataset with the child table if any.

Establish the relation between these two tables added to the dataset on the basis of the primary and foreign key relationship. (This can be achieved by taking a Relation object, instantiating it with parent child field information and adding it to the Relation collection of the Dataset.)

Repeat the previous two steps for each next child table if any. (The relation will be maintained between the current child and its immediate parent table.)

Now create the nodes of the tree recursively for each row of the Dataset’s parent table with all related rows of the Dataset’s child table under that primary key.

The following figure shows all the properties for XTreeView binding with database.

Figure 4

 

Now let us take a look at these properties that do the same job for us without writing any code. I have put these properties under a new category database in the property pane for the sake of simplicity and better understanding.

ConnectionString property is mandatory and required to be set with a valid connection string as shown below.

Listing 4

<cc1:XTreeView ID="XTreeView1" runat="server"
 ConnectionString="Data Source=gmohyd-serv;Initial Catalog=pakistan_db;Integrated Security=True"
......
</cc1:XtreeView>

Parent node has the following properties.

ParentTableName:  Name of the parent table.  (Mandatory)

ParentNodeTextField: Name of the field of parent table to be displayed as the node text. (Optional, if not set XtreeView takes the second column as node text field.)

ParentNodeValueField: Name of the field of parent table that has to be set as value. Value field can be used for saving page URL's if required, otherwise it is suitable to save ID's. (Optional, if not set, XtreeView takes the first column as node text field.)

ParentChildRelationField:  Name of the field (primary key) of parent table that is being used as foreign key in child table. (Mandatory if there is some child of it.)

The child has the following properties.

ChildTableName:  Name of the Child table.  (Mandatory)

ChildNodeTextField: Name of the field of Child table to be displayed as the node text. (Optional, if not set, XtreeView takes the second column as node text field.)

ChildNodeValueField: Name of the field of Child table that has to be set as value. Value field can be used for saving page URL's if required, otherwise it is suitable to save ID's. (Optional, if not set, XtreeView takes the first column as node text field.)

ChildParentRelationField:  Name of the field (foreign key) of the child table that is being used as primary key in parent table. (Mandatory)

ChildGrandChildRelationField:  Name of the field (primary key) of this immediate parent table that is being used as foreign key in grand child table. (Mandatory, if there is, it is child)

Grand Child has the following properties.

GrandChildTableName:  Name of the Grand Child table.  (Mandatory)

GrandChildNodeTextField: Name of the field of Grand Child table to be displayed as the node text. (Optional, if not set, XtreeView takes the second column as node text field.)

GrandChildNodeValueField: Name of the field of Grand Child table that has to be set as the value. Value field can be used for saving page URL's if required, otherwise it is suitable to save ID's. (Optional, if not set, XtreeView takes the first column as node text field.)

GrandChildChildRelationField:  Name of the field (foreign key) in the grand child table that is being used as primary key in immediate parent table. (Mandatory)

You may have noticed that most of the properties are optiona;l if you do not set them, they are set with default fields.  For binding XTreeView with relational database we need the following information:

Name of table(s)

Name of the relation field(s) with (immediate) parent and (immediate) child, a primary key field in case of parent table and foreign key field in case of child table.


View Entire Article

User Comments

Title: hi   
Name: masoud
Date: 2012-05-28 6:35:45 AM
Comment:
thank for you
Title: hi   
Name: enes
Date: 2011-05-18 8:22:06 AM
Comment:
thats realy good artical thank you .. But when i try with mdb it's not support have can i do ..thanks..
Title: Thanks alot..   
Name: vikram dhawan
Date: 2010-10-20 6:52:17 AM
Comment:
Thanks,i was looking for it the same thing.
God bless you..
keep writing more articles...
thanks again...
Title: Ok   
Name: Alberto
Date: 2010-07-30 4:45:45 PM
Comment:
Hello Mahr
your control is ok but I need it to be strong signed. I have to put the control in sharepoint page and, as you know, sharepoint does not like not signed assembly.
Can you help me?
Thanks
Alberto
Title: Code will not work   
Name: Tiger Woods
Date: 2010-04-06 1:54:17 PM
Comment:
FYI, if you use ImageSet="Simple"
Title: Where is the ExtendedXControls Code?   
Name: OutOfTouch
Date: 2010-02-20 5:43:03 PM
Comment:
Where is the code for the TreeView? All I see is a sample web using the exteneded controls dll?
Title: Expand Node on Mouse over   
Name: Mak
Date: 2008-08-07 5:14:46 PM
Comment:
I need a TreeView who's node will expand on mouse over.

Any View's ??
Title: SelectedIndex   
Name: Mark
Date: 2008-02-18 9:37:57 AM
Comment:
Hi Mahr,
Thanks for the reply. I read the article and it was very helpful in terms of learning the basics on how to extend a control. Thank you. The thing is that with the treeview webcontrol, as you mention in your article, is missing certain mission-critical functionality, such is when posting back it not showing the selected noded in the window, so each time the user has to scroll down. That's crazy-making. I looked at your extendedtreeview.dll in reflector to see if I could figure out how to get it to work properly when I extend the control, but to be honest, I couldn't put it together. Could you help me with this? It would be awesome if you can get me going. The only thing I care about at the moment with treeview is this retarded postback issue. Everything else I have working fine. Thank you!
Title: Re: It Dont Work   
Name: Mahr G. Mohyuddin
Date: 2008-01-26 1:02:32 AM
Comment:
Hi,

You have not read the artcile
You have not used the "value" property for keeping url. DONT use url property.
Title: It Dont Work   
Name: James
Date: 2008-01-25 12:20:29 PM
Comment:
Hi

Downloaded and replaced an existing tree view with yours. Works exactly as existing tree view, that’s the problem, it is not remembering its state.

Is there a website, page or control setting I need to set?
Title: Re: extendedtreeview.dll   
Name: Mahr G. Mohyuddin
Date: 2008-01-17 2:19:41 PM
Comment:
Hi Mark!
My another article "Developing Custom Controls Part 1" has recently been published. You may view it wwww.aspalliance.com/1526. It explains in detail the types of custom cotrols and the steps in detail required to develope custom controls ( extended one in first part , ExtendedTextBox ). although I have not made exended treeview as an example in this yet reading this article will let you know all required steps and their detail for extending any control.
Title: extendedtreeview.dll   
Name: mark
Date: 2008-01-17 8:05:22 AM
Comment:
Hi Mohyuddin,
Very cool. Just wondering, you mention "This article does not explain how to extend a TreeView control. That will be covered in a separate article"... just wondering, have you had a chance to publish that one? If so, could you post a link to it? That would be great. Thanks!
Title: Re: NO SaveExpandedState property   
Name: G. Mohyuddin
Date: 2007-12-06 3:06:40 AM
Comment:
Hi Mike,

Actually the Extended Treeview saves its state by default you won't need set any property. Earlier the property SaveExpandedState was there later it was excluded and I am sorry I could not remove it from article's text.

Do let me know, if you have any concern regarding this.

Regards.
Title: G. Mohyuddin   
Name: Re: Problem
Date: 2007-06-22 6:13:47 AM
Comment:
Hi,

You dont need to look for SaveExpansionState property. By default it supports treeview sate saving. Initially I provided this to turn it off/on but later i intentionally removed from code but forgot to remove it from documentation. use it u dont need to set any property for expansion sate saving.
Title: Problem   
Name: Nick
Date: 2007-06-22 4:21:53 AM
Comment:
Hi Just downloaded this,just what I need, SaveExpansionState, except this feature is missing. I have gone through all the options and cannot find the feature. According to your info above it should be between populatenodesfromclient and showcheckboxes, but it is not there. Help !!!!!
Title: Re: Great Work   
Name: G. Mohyuddin
Date: 2007-05-23 9:12:36 AM
Comment:
Thanks, Amir Mughal!
Title: Great Work   
Name: M Aamir Mughal
Date: 2007-05-23 8:57:13 AM
Comment:
ha!
great work man :)
keep it up ... (Y)
Title: Re:Nice Work   
Name: G. Mohyuddin
Date: 2007-05-23 2:32:35 AM
Comment:
Thanks! Waheed Aslam.
Title: Nice Work   
Name: Waheed Aslam Ghuman
Date: 2007-05-23 2:31:15 AM
Comment:
Great work G. Mohyuddin. Features added to treeview are really very useful and very much desired by most developers

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-18 5:34:36 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search