Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

I want to know how to create tree and display in same aspx page
Posted
Comments
Sunasara Imdadhusen 29-Oct-10 7:53am    
Please explain what you want? and where are you stuck.
Mohd Wasif 29-Oct-10 9:01am    
What kind of tree u r taking about.
Binary Tree,Tree View or something else.
Mehsud 30-Oct-10 1:10am    
it s a Treeview. I want to add nodes and links dynamically in treeview. so i need coding how to create and display

1 solution

Hi Mehsud,
It is easy to create nodes and adding them dynamically in TreeView.
First of all you need to add(Drag and Drop) a TreeView(say trvDepartment)control to the aspx page to which you add childnodes.

Assume that you have an Arraylist that has Employees Names which are added as Childnodes to Department Tree(trvDepartment).
The code looks like this

TreeNode tnEmp = null;
ArrayList arrEmp = new ArrayList();
arrEmp.Add("E1");
arrEmp.Add("E2");
arrEmp.Add("E3");
foreach(string Ename in arrEmp)
 {
tnEmp = new TreeNode();
tnEmp.Text = Ename;
trvDepartment.ChildNodes.Add(tnEmp);
trvDepartment.CollapseAll();
}

This way you can add Nodes to tree.
You can get the data into ArrayList from Database directly and create childnodes according to the rows returned.
Hope this helps... :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900