Friday, April 8, 2011

Can I skip nodes in ASP.NET Menu Control?

I have a web.sitemap like this:

<siteMapNode url="~/Default.aspx" title="Home" description="" >
    <siteMapNode title="Node 1" description="">
        <siteMapNode url="" title="Node 1-1" description="" />
        <siteMapNode url="" title="Node 1-2" description="" />
    </siteMapNode>
    <siteMapNode title="Node 2" description="">
        <siteMapNode url="" title="Node 2-1" description="" />
        <siteMapNode url="" title="Node 2-2" description="" />
    </siteMapNode>
</siteMapNode>

If I use an ASP.NET menu control (with StaticDisplayLevels=2), I get this:

| Home | Node 1 | Node 2 |

Is there a property for skipping "Home" and get this menu (from that sitemap):

| Node 1 | Node 2 |

?

From stackoverflow
  • If you aren't already using a SiteMapDataSource to populate the Menu, you can do that and set its ShowStartingNode property to false (and, as noted in the comment above, decrement the StaticDisplayLevels by 1, since you're removing a level) like this:

    <asp:SiteMapDataSource ID="MenuSource" runat="server" ShowStartingNode="false" />
    

    Of course, this only works for the root node. To skip other nodes or entire levels of nodes, it would be necessary to massage the source Xml before populating the Menu (for example, use some xslt to strip out a class of nodes).

  • If you are using a SiteMapsDataSource you can skip the root node by setting the ShowStartingNode property to false.

    Juan Manuel : Great, thanks. The property is in the DataSource, not the menu control where I was looking
    Juan Manuel : I also had to switch StaticDisplayLevels from 2 to 1, since the starting node is not showing now

0 comments:

Post a Comment