AllelfplacH
New Member
I have an ASP.NET \[code\]System.Web.UI.WebControls.TreeView\[/code\] in a UserControl project.Initially, I populate one root node at the initial load, which works as expected.After this, client-side interaction should drive the programmatic addition and removal of the child nodes.I add the nodes programmatically server-side, and can watch on the debugger the \[code\]TreeNode\[/code\] objects being created, and the \[code\]TreeNode.ChildNodes.Add()\[/code\] and \[code\].AddAt()\[/code\] functions run through with no exceptions. I can see the new objects in the \[code\]TreeNode.ChildNodes\[/code\] collection following this, but after the first root node populating initially, no other nodes will render in the browser.Like this:\[code\]TreeNode root = treeViewControl.FindNode(rootValue); // All values are goodTreeNode child = new TreeNode(text, value);// root.ChildNodes.Count == 0 hereroot.ChildNodes.Add(child);// root.ChildNodes.Count == 1 here// but nothing renders for the new node in the browser\[/code\]Also:\[code\]// root.ChildNodes.Count == 0 hereroot.ChildNodes.AddAt(0, child);// root.ChildNodes.Count == 1 here\[/code\]However:\[code\]treeViewControl.Nodes.Clear();TreeNode newRoot = new TreeNode(text, value);newRoot.ChildNodes.Add(new TreeNode(text, value));treeViewControl.Nodes.Add(newRoot);// This renders both new nodes in the browser...\[/code\]Why does the latter code render and work as expected, but adding to the ChildNodes collection as in the former does not?Edit:This code works:\[code\]treeViewControl.FindControl(rootValue).ChildNodes.Add(new TreeNode(text, value));treeViewControl.FindControl(pathToNewNode).ChildNodes.Add(new TreeNode(leafText, leafValue);\[/code\]So why doesn't the first set of code work, where you work with the object instead of chaining function calls together?