- 1
1.1
1.2
- 1.3
1.3.1
1.3.2
- 1.3.3
1.3.3.1
1.3.3.2
+ 2
+ 3
Hi All,
For example if we consider that the above mentioned is like Treeview,Here total 5 parent nodes are there those are
1,
1.3,
1.3.3,
2,
3
For Parent Nodes Like,
1
1.3
1.3.3
I wrote 3 for each loop’s if you observe in my code.
protected void tvCategories_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
try
{
foreach (TreeNode treenode in tvCategories.Nodes)
{
if (treenode.Text == e.Node.Text)
{
treenode.Expand();
treenode.ImageUrl = "~/Images/OpenedBookColorInBlue.png";
break;
}
foreach (TreeNode t in treenode.ChildNodes)
{
if (t.Text == e.Node.Text)
{
t.Expand();
t.ImageUrl = "~/Images/OpenedBookColorInBlue.png";
break;
}
foreach (TreeNode t1 in t.ChildNodes)
{
if (t1.Text == e.Node.Text)
{
t1.Expand();
t1.ImageUrl = "~/Images/OpenedBookColorInBlue.png";
break;
}
}
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.Write(ex.ToString());
}
}
protected void tvCategories_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
{
try
{
foreach (TreeNode treenode in tvCategories.Nodes)
{
if (treenode.Text == e.Node.Text)
{
treenode.Collapse();
treenode.ImageUrl = "~/Images/ClosedBookColorInBlue.png";
break;
}
foreach (TreeNode t in treenode.ChildNodes)
{
if (t.Text == e.Node.Text)
{
t.Collapse();
t.ImageUrl = "~/Images/ClosedBookColorInBlue.png";
break;
}
foreach (TreeNode t1 in t.ChildNodes)
{
if (t1.Text == e.Node.Text)
{
t1.Collapse();
t1.ImageUrl = "~/Images/ClosedBookColorInBlue.png";
break;
}
}
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.Write(ex.ToString());
}
}
Now For Example If my Treeview is like below mentioned,How many forech loops i want to write??
- 1
1.1
1.2
- 1.3
1.3.1
1.3.2
- 1.3.3
1.3.3.1
1.3.3.2
- 1.3.3.3
1.3.3.3.1
1.3.3.3.2
- 1.3.3.3.3
1.3.3.3.3.1
+ 2
+ 3
According to my code for the above mention treeview I want to write 5 for each loop’s
Suppose If i have n-parent nodes what can i do????
If i increase my code like that it will be bad & it gets too much lenthy code
so it is not correct naa.
So what was the solution for this???
Please give me...
Thanks in Advance,
VenkiDesai.k