ASP.NET Treeview control navigation - Help!

Associate
Joined
12 Jun 2006
Posts
164
Guys, need some help from experienced ASP.NET developers. I've got a Treeview control for side menu navigation on a website. It has been set only to shows nodes at the top level and not to show the collapse/expand icons.

The problem I am having is getting one of these ParentNodes on the top level to load the correct link and expand to shows its ChildNodes when clicked.

At the moment, when I click on the ParentNode, I am taken to the correct page but it does not expand to show its ChildNodes. I am using C# as the programming language. I have the standard Treeview control code with the ExpandDepth="0" and it gets its node information from the 'sitemap' file.

<asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" ExpandDepth="0"BackColor="#007CC2" ImageSet="Arrows" >

</asp:TreeView>

Can anyone tell me how I can do this? Thx :)
 
Associate
Joined
24 Jul 2003
Posts
1,420
Location
West Mids
Hmmm, I might be misunderstanding your problem, but if you're trying to expand the selected node:

Code:
TreeView1.SelectedNode.Expand();

Are the TreeView nodes posting back or are they actually linking to different pages?

I guess it depends on how your pages are set up. You could programmatically expand the correct node in each page if you know where they are in the tree:

Code:
//0 = index of node in the tree
TreeView1.Nodes[0].Expand();

If you don't then you could do a loop of some kind to try and identify the node:

Code:
foreach (TreeNode nodes in TreeView1.Nodes)
{
     if(nodes.Text == "myNode")
     {
          nodes.Expand();
     }
}

Not really sure what it is you need :)
 
Last edited:
Back
Top Bottom