Hi,
I want to set the selected node to the treeview on server side, I tried setting selected property to false but it's not working, and always root node is selected. How to set selectednode?
Thanks
Hello kotapati,
You need to set the selected nodes during a later phase of the WebDataTree lifecycle.
For example inside the PreRender event.
Except setting the node to be selected you need to add it to the SelectedNodes collection.
protected void WebDataTree1_PreRender(object sender, EventArgs e)
{
DataTreeNode node = (DataTreeNode)WebDataTree1.Nodes.FindNodeByText("Alfreds Futterkiste");
node.Selected = true;
WebDataTree1.SelectedNodes.Add(node);
// another way
WebDataTree1.Nodes[1].Selected = true;
WebDataTree1.SelectedNodes.Add(WebDataTree1.Nodes[1]);
}
Let me know if you need further assistance regarding this.
If we access node from WebDataTree1.Nodes it would give only root nodes only, suppose if I want to set the selected node as one of the child node of the root nodes. I tried to access child node from .AllNodes collection, but there is no way to find item from AllNodes. How do we find the node anywhere in the tree?