I currently have an IQueryable of Questions. In my Question object I have and "id" and a "parentId" which can be used to create a hierarchy. Currently, I bind a RadTreeView to the IQueryable of Questions and the RadTreeView takes care of creating the hierarchy because I define the dataId and dataParentId for the TreeView in the markup. I am now in need of actually having the data sorted into a hierarchy PRIOR to passing it off to my RadTreeView. How can I do this?
Asked
Active
Viewed 520 times
1
-
Please expand on what you mean by "sorted into a hierarchy". Are you wanting to create an actual object graph, or are you still thinking of it as tabular data? – Bryan Batchelder Dec 09 '09 at 16:39
-
Just as data. In my case, a List of Questions in hierarchical order. – Brian David Berman Dec 09 '09 at 17:05
2 Answers
1
You could add a numeric field to the table, and populate it by recursively walking the tree and filling the numeric field with an incrementing value.
ParentID ID Sequence
1 7 1
1 4 2
1 9 3
2 6 4
2 5 5
2 3 6
..etc.

Robert Harvey
- 178,213
- 47
- 333
- 501
-
That would just bring the parents to the top and the children to the bottom. I need it actually grouped like a hierarchy in the actual data. – Brian David Berman Dec 09 '09 at 16:38
-
-
You need some code that walks the tree in proper order, adding the incrementing number to the table as you go. – Robert Harvey Dec 09 '09 at 17:06
0
If you have access to the SQL Server, you can set something up using Common Table Expressions to return data in the proper order.. See:
http://a-kicker-n.blogspot.com/2009/04/how-to-sort-hierarchical-recursive.html
See also: Hierarchical data in Linq - options and performance

Community
- 1
- 1

Robert Harvey
- 178,213
- 47
- 333
- 501