LeonidasFett
LeonidasFett

Reputation: 3132

Removing root node of tree view for site map

i have a menu which sits on an asp.net page. i used a treeview control to display my sitemenu. only problem is i have a root node which practically does nothing.

currently my menu structure is as follows:

-empty root node
I---Home
I---Calendar
I---....

but i would like it like this:

-Home
-Calendar
-....

so basically the root node should be removed or hidden, as long as the user cant click and or see it...

is there a simple way of doing this? i tried removing the empty < siteMapNode > tag but this gives me an error...

Upvotes: 0

Views: 1332

Answers (1)

MikeSmithDev
MikeSmithDev

Reputation: 15797

There are properties in the SiteMapDataSource that help control this. Something like:

<asp:SiteMapDataSource ID="_siteMapData" runat="server" ShowStartingNode="false" StartFromCurrentNode="true" />
<asp:TreeView ID="_tree" NodeWrap="true" ExpandDepth="1" DataSourceID="_siteMapData" runat="server"></asp:TreeView>

Changing the value of ShowStartingNode should be what you need.

You can also change that value from the code-behind. This will change the initial node based on whether or not the current node has children or not (no children, go up a level):

SiteMapNode currNode = System.Web.SiteMap.CurrentNode;
_siteMapData.StartingNodeOffset = currNode != null && currNode.HasChildNodes ? 0 : -1;

Upvotes: 1

Related Questions