SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Guru pinch's Avatar
    Join Date
    Mar 2005
    Posts
    688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Treeview/SiteMapDataSource - Removing Nodes

    I use my web.sitemap file to help build my site navigation and I also use it on my 'Sitemap.aspx' page which simply displays the entire hierarchy in a TreeView.

    On my Sitemap.aspx page, I'm trying to hide those nodes in the web.sitemap that are used to 'edit' particular objects. These pages generally accept variables through the QueryString and are normally accessed through other pages in the application. Hence, it doesn't make sense to enter those pages directly so I need to remove them from the tree generated on my Sitemap.aspx page.

    I added a custom property to the nodes that need to be removed in my web.sitemap file (hideNode='true') but I can't seem to find a way to isolate those nodes during the binding process and not populate them in the TreeView.

    Is there any way to do this?

    Thanks

  2. #2
    SitePoint Guru pinch's Avatar
    Join Date
    Mar 2005
    Posts
    688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    FWIW, the best way to accomplish this is to first add an attribute to the fields you want to ignore in the web.sitemap file:

    Code ASP:
    			<siteMapNode showNode="false" url="~/admin/users/EditUserPersonal.aspx" title="EditUserPersonal" description="This page is used to edit user's personal information."/>

    Then, when binding the SMDS to the TreeView, intercept these nodes and immediately remove them from the tree after they're bound:

    Code ASP:
        protected void tvSitemap_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
        {
          SiteMapNode siteMapNode = (SiteMapNode)e.Node.DataItem;
          TreeNode treeNode = e.Node;
          if (siteMapNode["showNode"] == "false")
          {
            treeNode.Parent.ChildNodes.Remove(e.Node);
          }

    I'm out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •