kacalapy
kacalapy

Reputation: 10164

asp.net treeview expanding the root node and colapse the rest?

i have a databound treeview in asp.net. how can i expand the root node and have the rest of the tree nodes all colapsed?

thanks

Upvotes: 1

Views: 3429

Answers (2)

Riaan
Riaan

Reputation: 3552

To expand a parent at a time on click event, you can try the following code:

protected void tvMenu_SelectedNodeChanged(object sender, EventArgs e)
{
    TreeNode tn = tvMenu.SelectedNode;
    tn.ExpandAll();
}

Upvotes: 0

Matthew Jones
Matthew Jones

Reputation: 26190

Well, for the root node of the tree, you would do it like this:

TreeView1.CollapseAll();
TreeView1.Nodes[0].Expand();

Upvotes: 2

Related Questions