Search code examples
asp.netdatasettelerikiqueryablehierarchical

IQueryable into a hierarchy


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?


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.