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?
+1
A:
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
2009-12-09 16:31:09
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
2009-12-09 16:38:37
By golly you're right. Edited my answer.
Robert Harvey
2009-12-09 16:47:53
Still not following. How are you determining Sequence?
Brian David Berman
2009-12-09 17:01:00
You need some code that walks the tree in proper order, adding the incrementing number to the table as you go.
Robert Harvey
2009-12-09 17:06:32
A:
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: http://stackoverflow.com/questions/202912/hierarchical-data-in-linq-options-and-performance
Robert Harvey
2009-12-09 17:19:46