I have a TreeView in my code (Tree1) and i am going to add nodes in depth , using my CreatTree()
method. In Debug i understood that this line
(Tree1.Nodes[i].ChildNodes.Add(new TreeNode(i.ToString()))
) does not lead to adding a node to Tree so the error in the loop is:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Can anybody tell me how can i add a Child to a certain Node?
<asp:TreeView ID="Tree1" runat="server" >
</asp:TreeView>
The code behind is:
protected void CreateTree( )
{
Tree1.Nodes.Add(new TreeNode("0"));
for (int i = 0; i < 4; i++)
Tree1.Nodes[i].ChildNodes.Add(new TreeNode(i.ToString()));;
}