English 中文(简体)
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?

最佳回答

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.

问题回答

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





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签