Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. SiteMapPath: Don’t show the root level in breadcrumb

SiteMapPath: Don’t show the root level in breadcrumb

Scheduled Pinned Locked Moved ASP.NET
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anderslundsgard
    wrote on last edited by
    #1

    How do I customise the behaviour of the asp:SiteMapPath to not show the root siteMapNode as a part of the breadcrumb.

    <siteMapNode title="Root"…>
    <siteMapNode title="Level_1_1"…>
    </siteMapNode>
    <siteMapNode title="Level_1_2"…>
    <siteMapNode title="Level_2_1"…>
    </siteMapNode>
    </siteMapNode>
    </siteMapNode>

    Shold in the breadcrumb look like: Level_1_2 > Level_2_1 and not: Root > Level_1_2 > Level_2_1

    _____________________________ ...and justice for all

    P 1 Reply Last reply
    0
    • A anderslundsgard

      How do I customise the behaviour of the asp:SiteMapPath to not show the root siteMapNode as a part of the breadcrumb.

      <siteMapNode title="Root"…>
      <siteMapNode title="Level_1_1"…>
      </siteMapNode>
      <siteMapNode title="Level_1_2"…>
      <siteMapNode title="Level_2_1"…>
      </siteMapNode>
      </siteMapNode>
      </siteMapNode>

      Shold in the breadcrumb look like: Level_1_2 > Level_2_1 and not: Root > Level_1_2 > Level_2_1

      _____________________________ ...and justice for all

      P Offline
      P Offline
      Prosanta Kundu online
      wrote on last edited by
      #2

      Place the following code in Global.asax:

      void Application_Start(object sender, EventArgs e)
      {
      //
      // Register a handler for SiteMap.SiteMapResolve events to hide the
      // root node from SiteMapPath controls.
      //
      SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(HideRootNode);
      }

      static SiteMapNode HideRootNode(Object sender, SiteMapResolveEventArgs e)
      {
      //
      // Hide the root node from SiteMapPath controls by cloning the site
      // map from the current node up to the node below the root node and
      // setting that node's ParentNode property to null.
      //
      SiteMapNode node = SiteMap.CurrentNode.Clone();
      SiteMapNode current = node;
      SiteMapNode root = SiteMap.RootNode;

      if (current != root) // Just in case the current node \*is\* the root node!
      {
          while (node.ParentNode != root)
          {
              node.ParentNode = node.ParentNode.Clone();
              node = node.ParentNode;
          }
          node.ParentNode = null;
      }
      return current;
      

      }

      A 1 Reply Last reply
      0
      • P Prosanta Kundu online

        Place the following code in Global.asax:

        void Application_Start(object sender, EventArgs e)
        {
        //
        // Register a handler for SiteMap.SiteMapResolve events to hide the
        // root node from SiteMapPath controls.
        //
        SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(HideRootNode);
        }

        static SiteMapNode HideRootNode(Object sender, SiteMapResolveEventArgs e)
        {
        //
        // Hide the root node from SiteMapPath controls by cloning the site
        // map from the current node up to the node below the root node and
        // setting that node's ParentNode property to null.
        //
        SiteMapNode node = SiteMap.CurrentNode.Clone();
        SiteMapNode current = node;
        SiteMapNode root = SiteMap.RootNode;

        if (current != root) // Just in case the current node \*is\* the root node!
        {
            while (node.ParentNode != root)
            {
                node.ParentNode = node.ParentNode.Clone();
                node = node.ParentNode;
            }
            node.ParentNode = null;
        }
        return current;
        

        }

        A Offline
        A Offline
        anderslundsgard
        wrote on last edited by
        #3

        Thanks, This little css-hack also made it for me: .PageHeading > a:first-child + span + span { display: none; }

        _____________________________ ...and justice for all

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups