This is a migrated thread and some comments may be shown as answers.

Hierarchy Treeview...

6 Answers 122 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Chamira
Top achievements
Rank 1
Chamira asked on 07 Oct 2008, 12:31 PM
Im having three tables with schema

Category ( CategoryID , CategoryName )
SubCategory ( SubCategoryID, CatgoryID_Fk , SubCategoryName)    (Foreign Key to Category Table )
Items (ItemID , SubCategoryID_Fk , ItemName) ( Foreign Key to Sub Cat table )

here is the database diagram .. if i didnt make myself clear..

http://img122.imageshack.us/img122/149/imagezp3.jpg

So what i want is in the tree view to show the
Categories first and once expanded show the subcategories that fall under the sub categories

and for example if a category exists with the name "GAMES"

it should show the number of items that is under GAMES

for example

+ GAMES (11)
+ Electronix ( 23 )

Thanks in advance...





6 Answers, 1 is accepted

Sort by
0
Serrin
Top achievements
Rank 1
answered on 07 Oct 2008, 01:01 PM
Hey Chamira, 

Just so I wrap my head around this a little more, are you looking to do load on demand, or are you generating this dynamically when the page loads?  Trying to figure out where you are coming from so I can possibly help with a solution. :)
0
Chamira
Top achievements
Rank 1
answered on 07 Oct 2008, 01:15 PM
thanks sherrin :)

its dynamically.. as in getting the information from the database..

thanks :)
0
Chamira
Top achievements
Rank 1
answered on 09 Oct 2008, 07:30 AM
any luck on this ... ??

thanks ..
0
Aleksandar
Top achievements
Rank 1
answered on 09 Oct 2008, 09:30 AM
It looks like what you call dynamicaly is not dynamicaly. Dynamicaly (or Load on demand) would be if you call new binding for each clicked node. To be more precise: OnLoad you add two nodes to TreeView, then when user clicks one of the nodes, you postback and load sub nodes for that node.
My understanding is that you just need hyerarchical data loaded from your 3 tables. Key to what you need to do is as follows:
-Declare a new DataTable in your CodeBehind (dim objTable as new system.Data.DataTable)
Make at least 4 columns - DataFieldID, DataFieldParentID, DataTextField, DataValueField (you can call them differently)
-Now, you can make 3 queries and load data from each table separately or you can make one querie and load data from all tables all in one go.
-For tbl_category items: make sure DataFieldParentID stays Nothing (if you use VB),  DataFieldID is CategoryId and DataTextField is CategoryName. (Do not try to find this in documentation, it is not there). The rest for this table is up to you and depends on TreeView functionality.
-For tbl_SubCategory, make sure DataFieldParentID  is field CategoryID, DataFieldID is SubCategoryID and DataTextField  is SubCategoryName
-tbl_Items - DataFieldParentID  is field SubCategoryID, DataFieldID is ItemID and DataTextField  is ItemName. Now, you did not show complete tbl_Items (copyrights?), so I am just guesing what is there.
Next:
-After finished loading your DataTable in code behind, give it as DataSource to your RatTreeView (RadTreeView1.DataSource=objTable) and bind RadTriView (RadTreeView1.Bind()).
In ASPX file (can be in code behind as well, but easier in ASPX), set the following values to your RadTreeView:
    DataFieldID="DataFieldID" 
    DataFieldParentID="DataParentFieldID" 
    DataTextField="DataTextField" 
    DataValueField="DataValueField" 

I hope I was clear enough. Just trying to save some time to Telerik people, so they can answer my open questions :)

Regards,
Aleksandar

0
Chamira
Top achievements
Rank 1
answered on 09 Oct 2008, 09:44 AM
Hi Alex thanks for the response..

can u please explain wat u mean by this part...

-Now, you can make 3 queries and load data from each table separately or you can make one querie and load data from all tables all in one go.
-For tbl_category items: make sure DataFieldParentID stays Nothing (if you use VB),  DataFieldID is CategoryId and DataTextField is CategoryName. (Do not try to find this in documentation, it is not there). The rest for this table is up to you and depends on TreeView functionality.
-For tbl_SubCategory, make sure DataFieldParentID  is field CategoryID, DataFieldID is SubCategoryID and DataTextField  is SubCategoryName
-tbl_Items - DataFieldParentID  is field SubCategoryID, DataFieldID is ItemID and DataTextField  is ItemName. Now, you did not show complete tbl_Items (copyrights?), so I am just guesing what is there.


Where do i specify these ...???



0
Aleksandar
Top achievements
Rank 1
answered on 09 Oct 2008, 10:11 AM
You have to load data from your database tables and to arrange it into the DataTable object (I named it objTable) in your code behind.You can do that by using 3 AccessDataSource controlls (easy), where you load each database table separately into yourr objTable object (all in code behind). You have to follow rules for hyerarchical data representation used in RadTreeView. Shortly: CategoryID is top parent and has no parents, their DataFieldParentID  is Nothing (in VB).SubCategoryID is child of a parent CategoryID and their  DataFieldParentID   is CategoryID from tbl_Category. Items are child elements of CategoryID and their DataFieldParentID is SubCategoryID from tbl_Items.

Steps
-Make 3 AccessDataSource objects. Load results into separate DataTable objects
-Define objTable as System.Data.DataTable and give it at least 4 columns I listed before.
-Load data from 3 table objects (from first step) into objTable (second step. Follow the rules outlined at the begining of this replay and in previous replay.
-Ad code from previous replay to your TreeView object,
-Assign objTable as DataSource to your TreeView,
-Bind TreeView (TreeView1.Bind)
Done.

Sory I do not have time to give you full code for all this, but it should not be too complicated at all. I am sure Telerik people will have something similar on file.

Regards,
Alex
Tags
TreeView
Asked by
Chamira
Top achievements
Rank 1
Answers by
Serrin
Top achievements
Rank 1
Chamira
Top achievements
Rank 1
Aleksandar
Top achievements
Rank 1
Share this question
or