1

I have a table structure like this.

id | Name | ParentId

so for example:

id | Name     | ParentId 
------------------------- 
1  | Alice    | 0 
2  | Bob      | 0 
3  | Charlie  | 1 
4  | David    | 2 

where 'Alice' and 'Bob' are Parent nodes( which has Id = 0) and Alice has a child node named 'Charlie' and 'Bob' has a child node named 'David'. My question is, I need to retrieve the parent separately and the children in a collection. The 'Children' collection can have multiple parents and its children. Can anyone send me a code snippet using which I can retrieve Data from the database and populate the tree.

2
  • Which treeview control are you using? The default that ships with ASP.NET or a jQuery treeview plugin? Commented Jul 7, 2010 at 10:42
  • I see you edited the question. Even for jquery my code should be valid (with slight modification). Commented Jul 7, 2010 at 19:21

1 Answer 1

1

Similar to How to populate treeview except the classes used will be from the System.Web.UI.WebControls namespace (they are named the same).

Also BeginUpdate and EndUpdate methods don't exist for obvious reasons.

Sign up to request clarification or add additional context in comments.

1 Comment

It is usually not a good idea to use server controls in a asp.net mvc application. And this task is (at least in my opinion) a lot easier without server controls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.