Hide the root node of a SiteMapProvider ONLY into Menu control

Last post 07-03-2009 10:50 AM by moroandrea. 8 replies.

Sort Posts:

  • Hide the root node of a SiteMapProvider ONLY into Menu control

    07-02-2009, 10:02 AM
    • Member
      point Member
    • moroandrea
    • Member since 05-31-2007, 3:00 AM
    • Posts 24

    Hi Guys

    I read so much post about this specific and done so much test that I think my last chance is to ask you help.

    First of all my scenario: I need to hide root node (continuing to display the childrens) as well as internal nodes according to a custom param ShowOnMenu that I added into the web.sitemap.

    To achieve results I do web control with two asp.net controlsconfigured in this way

    <asp:Menu ID="SiteMenu" runat="server"
        DataSourceID="menuDataSource"
        ItemWrap="true"
        onmenuitemdatabound="MenuItemDataBound"
        oninit="MenuInit"    
        StaticDisplayLevels="20"
        ShowStartingNode="false">
    </asp:Menu>
    <asp:SiteMapDataSource runat="server" ID="menuDataSource" ShowStartingNode="false" />

    Overriding the MenuInit and MenuItemDataBound and using the e.Item.Parent.ChildItems.Remove(e.Item); into the bound event, I'm able to strip out the second level menu from the provider without displaying it.

    Unfortunately this is not possible with root node, because e.Item.Parent result in a null variable

    During my tests I was able to setup the root node to diabled (actually I don't remember how I did) and that is the best solution I achieved.

    If, in some other way I remove the Root Node, all the rest of childnodes are skipped as well and that's not what I want.

    I was thinking to act on the CSS friendly menu adapter file, trying to identify the custom param, but on that stage there is no direct reference for the XML file loaded into memory, just for the built menu to be rendered.

    I was thining to add a CssClassName param to let me operate in the CSS Friendly menu adding some stylesheet rules, but dunno how to do this.


    I'm really going into panic. Any idea and useful suggestion?

    Thanks

  • Re: Hide the root node of a SiteMapProvider ONLY into Menu control

    07-02-2009, 11:30 AM
    Answer
    • Participant
      1,547 point Participant
    • ctheriault
    • Member since 04-10-2009, 4:33 PM
    • Posts 276

    Having ShowStartingNode set to "False" in asp:SiteMapDataSource is enough for me to Hide the root menu.

    Unlike asp:SiteMapDataSource, asp:Menu is not supporting (or paying attention to) ShowStartingNode attribute; it is pointless to define it in there.

    This datasource is basicaly an XML datasource and XML must have a single root node by design; if you remove it, you either remove all its children nodes, or keep only one of its children nodes which will become the new root.

     

     

     

    ----
    Don't forget to mark this posting as an "Answer" if it is helpful to you
  • Re: Hide the root node of a SiteMapProvider ONLY into Menu control

    07-03-2009, 2:48 AM
    • Member
      point Member
    • moroandrea
    • Member since 05-31-2007, 3:00 AM
    • Posts 24

    Well the point is if that I remove one node, I immediately prevent all the childrens to be displayed. It could be a good solutions if I'm able to find a way to intercat with my inmemory sitemap. But Sitemap class, doesn't seem to allow this kind of interaction.

    If I work with sitemapnodecollection, I can change the inline content, but not to hide the node. Was so difficult add a visible property?

  • Re: Hide the root node of a SiteMapProvider ONLY into Menu control

    07-03-2009, 3:55 AM
    Answer
    • All-Star
      16,458 point All-Star
    • Dave Sussman
    • Member since 06-17-2002, 11:53 AM
    • UK
    • Posts 2,283
    • ASPInsiders
      TrustedFriends-MVPs

    Using ShowStartingNode is the accepted way of not showing the root node. When set the site map data source just doesn't expose the root node to any controls bound to it. You can also set MaximumDynamicDisplayLevels="0" on the menu and it will not show any dynamic menus, thus limiting you to the single set of nodes at the level below the root.

  • Re: Hide the root node of a SiteMapProvider ONLY into Menu control

    07-03-2009, 4:15 AM
    • Member
      point Member
    • moroandrea
    • Member since 05-31-2007, 3:00 AM
    • Posts 24

    Hi

    thanks for your reply. That's not exactly what I need.

    My menu tree is like this

    <siteMapNode>
        <siteMapNode url="~/administration/default.aspx" title="Amministrazione">
          <siteMapNode url="~/administration/website.aspx" title="CMS Setup" />
        </siteMapNode>
        <siteMapNode title="Home" url="~/home.aspx" ShowOnMenu="True">
        </siteMapNode>
        <siteMapNode title="Staff" url="~/staff.aspx" visible="True" ShowOnMenu="False" RootLevel="1" >
          <siteMapNode title="referenze" url="~/staff/referenze.aspx" />
          <siteMapNode title="organigramma" url="~/staff/organigramma.aspx" visible="True" />
          <siteMapNode ...
        </sitemapNode>
    </siteMapNode>

    so, suppose I want to hide the node with Staff Title, but show the childrens ... how can I do this?

  • Re: Hide the root node of a SiteMapProvider ONLY into Menu control

    07-03-2009, 4:30 AM
    • All-Star
      16,458 point All-Star
    • Dave Sussman
    • Member since 06-17-2002, 11:53 AM
    • UK
    • Posts 2,283
    • ASPInsiders
      TrustedFriends-MVPs

    Oh right, in that case use the MenuItemData Bound technique and check for the ShowOnMenu attribute, then remove the items. You can't remove the root node though, so you either need to use ShowStartingNode or have the menu item present but not visible; it's just that the menu automatically bind to the node elements, so if the node is present it gets bound to. Why doesn't using ShowStartingNode="false" work for you?

  • Re: Hide the root node of a SiteMapProvider ONLY into Menu control

    07-03-2009, 10:38 AM
    • Participant
      1,547 point Participant
    • ctheriault
    • Member since 04-10-2009, 4:33 PM
    • Posts 276

     Menu structure is pretty tigthly linked to the XML. There are several option more or less neat / sloppy...

    1] For instance a neat way would be to clone the initial XML structure (let's call it "XML template") and them reorganize it, by removing the Staff node only and move up its child nodes.

    2] Since a node cannot be hidden the proper, let's try ways to make it disappear (in MenuItemDataBound event): such as changing it's title to emptyString, collapsing its height to zero, changing the color of the font to the color of the background, ...

    3] Why don't you use 2 site maps; one with and one without "staff" node?

    ----
    Don't forget to mark this posting as an "Answer" if it is helpful to you
  • Re: Hide the root node of a SiteMapProvider ONLY into Menu control

    07-03-2009, 10:47 AM
    • Member
      point Member
    • moroandrea
    • Member since 05-31-2007, 3:00 AM
    • Posts 24

    Infact I can't remove the root node, but thanks to your suggestion (StartFromCurrentNode) and reingegnerizing the code I got my expected result.

  • Re: Hide the root node of a SiteMapProvider ONLY into Menu control

    07-03-2009, 10:50 AM
    • Member
      point Member
    • moroandrea
    • Member since 05-31-2007, 3:00 AM
    • Posts 24

    ctheriault:

     Menu structure is pretty tigthly linked to the XML. There are several option more or less neat / sloppy...

    1] For instance a neat way would be to clone the initial XML structure (let's call it "XML template") and them reorganize it, by removing the Staff node only and move up its child nodes.

    2] Since a node cannot be hidden the proper, let's try ways to make it disappear (in MenuItemDataBound event): such as changing it's title to emptyString, collapsing its height to zero, changing the color of the font to the color of the background, ...

    3] Why don't you use 2 site maps; one with and one without "staff" node?


    Solution 1 was something I was trying to do, but I was unable to get any good result. Anyway, now I got what I want. thanks to all for the suggestion.

Page 1 of 1 (9 items)