Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top