Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 treeview w/ drill down/into data

Author  Topic 

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2007-08-13 : 13:51:48
What I'd like to do is use a tree view on some route to help allow users to drill down into their data.



For instance, we have a table w/ 100 numbers, and they're nvarchar(100).



For simplicity sake, 50 start with D1, and the other 50 start with E1.



Under the 50 that start with D1, they are grouped by a dot and some more characters up to the next dot:

1. D1.01

2. D1.02

3. D1.03

4. D1.04

5. D1.05



When the page first loads, the 2 nodes would show:

D1

E1



..and if the user clicked D1, they'd see new nodes which took the next chars up to any next "dot" and listed the groupings/nodes like above.

1. D1.01

2. D1.02

3. D1.03

4. D1.04

5. D1.05



..and if the user clicked on D1.02, and the data would show like:

1. D1.02.01

2. D1.02.02

3. D1.02.03



...and if the user clicked on D1.02.03, they would see new nodes of:

1. D1.02.03.001

2. D1.02.03.02

3. D1.02.03.03B

..or something like that. Basically, each time the user clicks the node, we show a "dot" and two more characters...or up to the next "dot".

I have the tree view working now, but it's pretty much a one-for-one, and that's not very helpful for this scenario.

Thanks!

jhermiz

3564 Posts

Posted - 2007-08-13 : 15:29:14
Basically this is a parent child relationship. The roots have ParentID = null, while each child has its own set of ParentID's.
Consider the following example using your D1.
D1 which seperates into D1.01, D1.02, D1.03 etc. D1.02 seperates into D1.02.01, D1.02.02..etc.

So in the table you have the following


ParentID | ChildID
NULL D1
D1 | D1.01
D1 | D1.02
D1 | D1.03
...
D1.02 | D1.02.01
D1.02 | D1.02.02
D1.02 | D1.02.03
...
D1.02.01 | D1.02.01.XX
etc etc


So now you have a logical structure, so you simply fill the tree upto how far down the tree might go. To set parents you simply select the rows where the parentid is null. When they click on the parentid you load the nodes of the children of that parent by passing it what was selected, namely the ParentID. And you continue to do this until you have 0 rows returned.

make sense ?

Programmers HowTo's -- [url]http://jhermiz.googlepages.com[/url]
Go to Top of Page

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2007-08-13 : 18:09:05
Hi jhermiz,

Our table as it sits right now, has the column (which is a primary key / nvarchar(100)) in question looking like:

D1
D1.01
D1.01.01
D1.01.01.02
D1.01.01.02.003
D1.01.02
D1.01.02.02
D1.01.02.03
E1
E1.01
E1.01.01
E1.01.01.02.003
E1.01.02
E1.01.02.02
E1.01.02.033
E1.01.02.04

So, I'm thinking I have to look for the first "dot" and pull out the characters before that for the first node....then look for the 2nd "dot" and pull every thing before that for the second drill down node. Does that make sense? I think there's a strip or some function to do that, but I'm a bit stumped right now.

Any suggestions are welcome!

Thanks!
Go to Top of Page

jhermiz

3564 Posts

Posted - 2007-08-15 : 00:30:14
Why cant you make relationships out of this table? Can you not add additional tables or modify the existing system? Your existing table does not follow 3NF form. When you start noticing that you have to use SUBSTRINGs, INSTR's, LEFT, RIGHT, MID, UPPER, LOWER, all these functions in your db code or even your front end code then something is wrong. Read about the Third Normal Form and think about your current setup. After all a database is used to create relationships in your data. My example gave you a very simple way to relate a child to a parent. Your code would be much simplier.

As for how you do it with what you currently have, I don't know since I would not do it that way. Sorry.

Weblog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page
   

- Advertisement -