I have a page that needs to have a treeview that is populated from a database. Below is a little bit of code that i have been playing with. I would like the data in the hashtables to look like this if it were to work correctly.
Parent1
- Child 1
- Lvl 1
Parent2
- Child 2
- Lvl 2
and so on....
All the data I have is coming from different datatables for each lvl Parent child ect. Not like it s displayed below with hashtables.
Hashtable x = new Hashtable();
Hashtable y = new Hashtable();
Hashtable z = new Hashtable();
TreeNode Parent = new TreeNode();
TreeNode Child = new TreeNode();
x.Add(0, "Parent 1");
x.Add(1, "Parent 2");
x.Add(2, "Parent 3");
x.Add(3, "Parent 4");
y.Add(0, "Child 1");
y.Add(1, "Child 2");
y.Add(2, "Child 3");
y.Add(3, "Child 4");
z.Add(0, "Lvl 1");
z.Add(1, "Lvl 2");
z.Add(2, "Lvl 3");
z.Add(3, "Lvl 4");
for (int i = 0; i <= x.Count - 1; i++)
{
Parent = new TreeNode(x.ToString(), "Value");
for (int j = 0; j <= y.Count - 1; j++)
{
Child.ChildNodes.Add(new TreeNode(z[j].ToString(), "Val"));
Parent.ChildNodes.Add(new TreeNode(y[j].ToString(), "ChildValue"));
}
TreeView1.Nodes.Add(Parent);
}
Thanks for any help or advise!
Parent1
- Child 1
- Lvl 1
Parent2
- Child 2
- Lvl 2
and so on....
All the data I have is coming from different datatables for each lvl Parent child ect. Not like it s displayed below with hashtables.
Hashtable x = new Hashtable();
Hashtable y = new Hashtable();
Hashtable z = new Hashtable();
TreeNode Parent = new TreeNode();
TreeNode Child = new TreeNode();
x.Add(0, "Parent 1");
x.Add(1, "Parent 2");
x.Add(2, "Parent 3");
x.Add(3, "Parent 4");
y.Add(0, "Child 1");
y.Add(1, "Child 2");
y.Add(2, "Child 3");
y.Add(3, "Child 4");
z.Add(0, "Lvl 1");
z.Add(1, "Lvl 2");
z.Add(2, "Lvl 3");
z.Add(3, "Lvl 4");
for (int i = 0; i <= x.Count - 1; i++)
{
Parent = new TreeNode(x.ToString(), "Value");
for (int j = 0; j <= y.Count - 1; j++)
{
Child.ChildNodes.Add(new TreeNode(z[j].ToString(), "Val"));
Parent.ChildNodes.Add(new TreeNode(y[j].ToString(), "ChildValue"));
}
TreeView1.Nodes.Add(Parent);
}
Thanks for any help or advise!