I have a Sitemap with SiteMapNodes 1, 2, 3 and 4. I have a treeview on a page that is connected to this Sitemap. When the page loads, I do not want item 2 to appear. I still need to include Item 2 in my Sitemap so that it will appear in my SiteMapPath that
I use on all pages. How can I do this in my codebehind?
<siteMapNode
url="addenrollment.aspx"
title="add enrollment"
description="add enrollment"/>
<siteMapNode
url="addclubenrollment.aspx"
title="add club enrollment"
description="add club enrollment"/>
<siteMapNode
url="reenrollenrollment.aspx"
title="reenroll club member"
description="reenroll club member"/>
<siteMapNode
url="editenrollment.aspx"
title="edit club member"
description="edit club member"/>
<siteMapNode
url="viewenrollment.aspx"
title="view club member"
description="view club member"/>
<siteMapNode
url="deleteenrollment.aspx"
title="delete club member"
description="delete club member"/>
</
siteMapNode>
On enrollments.aspx I have a treeview connected to a SiteMapDataSource as follows:
<
asp:TreeView
ID="TreeView1"
runat="server"
DataSourceID="SiteMapDataSource1"
ImageSet="Simple"
NodeIndent="10">
<ParentNodeStyle
Font-Bold="False"
/>
<HoverNodeStyle
Font-Underline="True"
ForeColor="#DD5555"
/>
<SelectedNodeStyle
Font-Underline="True"
HorizontalPadding="0px"
VerticalPadding="0px"
ForeColor="#DD5555"
/>
<NodeStyle
Font-Names="Verdana"
Font-Size="8pt"
ForeColor="Black"
HorizontalPadding="0px"
NodeSpacing="0px"
VerticalPadding="0px"
/>
</asp:TreeView>
<asp:SiteMapDataSource
ID="SiteMapDataSource1"
runat="server"
StartFromCurrentNode="True"
/>
When enrollments.aspx is loaded, I don't want "add club enrollment" to appear in the treeview. How can I acheive this?
Strangely, when I add this to the scripts in the head of my aspx page right after the page load, nothing happens to my TreeView'd sitemap on the page. I substituted a real title for "Default2" (and changed the TreeView1 name to mine, TreeViewSM), and absolutely
nothing changes on the page.
And my Web.config SiteMapProvider info in the System.Web section:
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<providers>
<add name="XmlSiteMapProvider"
description="SiteMap provider which reads in .sitemap XML files."
type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
siteMapFile="Web.sitemap"
securityTrimmingEnabled="true"/>
</providers>
</siteMap>
I've been trying to figure this out for hours and I honestly don't know what I'm doing wrong. The site map info displays on the page as per my treeview, and my sitemappath (breadcrumbs) work fine on ever page. But I can't get this to hide the TreeView node(s)
I want to hide on my site map page. Any help would be appreciated.
Anyone? I can't get this to work at all with my page. I even tried a stripped-down version/page and it won't even work with that. Are there any know conflicts between ASP.NET versions? Here's my "stripped-down" page code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Could anyone who actually got this working please please PLEASE post their code from their Web.sitemap, Web.config and actual page files?!? I've tried entering in the code on this page exactly as the original poster had it with the script altered only to
include the proper TreeView id number and the title of the node to be hidden, AND IT DOESN'T WORK.
mandercruso
Member
19 Points
68 Posts
Treeview hide sitemap node...
Sep 25, 2007 02:45 PM|LINK
I have a Sitemap with SiteMapNodes 1, 2, 3 and 4. I have a treeview on a page that is connected to this Sitemap. When the page loads, I do not want item 2 to appear. I still need to include Item 2 in my Sitemap so that it will appear in my SiteMapPath that I use on all pages. How can I do this in my codebehind?
Thanks in advance,
Amanda
GillouX
Contributor
2330 Points
606 Posts
Re: Treeview hide sitemap node...
Sep 26, 2007 06:28 AM|LINK
can you give us an example because I don't follow you so well
Coppermill
Member
747 Points
185 Posts
Re: Treeview hide sitemap node...
Sep 26, 2007 11:57 AM|LINK
One way would be to create a method to read all the elements of the sitemap and then bind the method using a List to your DDL.
This way you can control what is being shown or not shown.<<<Bryan Avery>>>
Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
mandercruso
Member
19 Points
68 Posts
Re: Treeview hide sitemap node...
Sep 26, 2007 01:50 PM|LINK
Let me try to explain it better using code examples.
My sitemap contains:
<siteMapNode url="enrollments.aspx" title="enrollments" description="enrollments"><siteMapNode url="addenrollment.aspx" title="add enrollment" description="add enrollment"/>
<siteMapNode url="addclubenrollment.aspx" title="add club enrollment" description="add club enrollment"/>
<siteMapNode url="reenrollenrollment.aspx" title="reenroll club member" description="reenroll club member"/>
<siteMapNode url="editenrollment.aspx" title="edit club member" description="edit club member"/>
<siteMapNode url="viewenrollment.aspx" title="view club member" description="view club member"/>
<siteMapNode url="deleteenrollment.aspx" title="delete club member" description="delete club member"/>
</
siteMapNode>On enrollments.aspx I have a treeview connected to a SiteMapDataSource as follows:
<
asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" ImageSet="Simple" NodeIndent="10"> <ParentNodeStyle Font-Bold="False" /><HoverNodeStyle Font-Underline="True" ForeColor="#DD5555" />
<SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" ForeColor="#DD5555" />
<NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="0px" NodeSpacing="0px" VerticalPadding="0px" /> </asp:TreeView> <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" StartFromCurrentNode="True" /> When enrollments.aspx is loaded, I don't want "add club enrollment" to appear in the treeview. How can I acheive this?
Amanda Wang ...
All-Star
30008 Points
3104 Posts
Re: Treeview hide sitemap node...
Sep 27, 2007 06:50 AM|LINK
Hi Amanda,
You can the remove method of the treeview to remove the node that you donot want to display, adn the will not change the sitemap file.
Below is a sample:
protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e) { System.Web.UI.WebControls.TreeView tree = (System.Web.UI.WebControls.TreeView)sender; SiteMapNode mapNode = (SiteMapNode)e.Node.DataItem; if (mapNode.Title == "Default2") { System.Web.UI.WebControls.TreeNode parent = e.Node.Parent; if (parent != null) { parent.ChildNodes.Remove(e.Node); } } }Hope it helps.Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
mandercruso
Member
19 Points
68 Posts
Re: Treeview hide sitemap node...
Sep 27, 2007 02:10 PM|LINK
That was it. Thanks so much!
ovaisgeo
Member
402 Points
141 Posts
Re: Treeview hide sitemap node...
Jan 21, 2008 11:46 AM|LINK
its working great
IronWill
Member
57 Points
138 Posts
Re: Treeview hide sitemap node...
May 29, 2009 09:33 PM|LINK
Strangely, when I add this to the scripts in the head of my aspx page right after the page load, nothing happens to my TreeView'd sitemap on the page. I substituted a real title for "Default2" (and changed the TreeView1 name to mine, TreeViewSM), and absolutely nothing changes on the page.
Here's my TreeView and SiteMapDataSource code:
<asp:TreeView ID="TreeViewSM" runat="server" DataSourceID="SiteMapDataSourceSM" ShowLines="True" ExpandDepth="1" />
<asp:SiteMapDataSource ID="SiteMapDataSourceSM" runat="server" />
And here's a sample of my Web.sitemap file:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/default.aspx" title="Home" description="Library Home Page">
<siteMapNode url="~/Classic TV.aspx" title="Classic TV" description="Classic TV" />
<siteMapNode url="~/ContactUs.aspx" title="Contact Us" description="Contact Us" />
etc...
And my Web.config SiteMapProvider info in the System.Web section:
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<providers>
<add name="XmlSiteMapProvider"
description="SiteMap provider which reads in .sitemap XML files."
type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
siteMapFile="Web.sitemap"
securityTrimmingEnabled="true"/>
</providers>
</siteMap>
I've been trying to figure this out for hours and I honestly don't know what I'm doing wrong. The site map info displays on the page as per my treeview, and my sitemappath (breadcrumbs) work fine on ever page. But I can't get this to hide the TreeView node(s) I want to hide on my site map page. Any help would be appreciated.
IronWill
Member
57 Points
138 Posts
Re: Treeview hide sitemap node...
Jun 08, 2009 07:48 PM|LINK
Anyone? I can't get this to work at all with my page. I even tried a stripped-down version/page and it won't even work with that. Are there any know conflicts between ASP.NET versions? Here's my "stripped-down" page code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void TreeViewSM_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
System.Web.UI.WebControls.TreeView tree = (System.Web.UI.WebControls.TreeView)sender;
SiteMapNode mapNode = (SiteMapNode)e.Node.DataItem;
System.Web.UI.WebControls.TreeNode itemToRemove = tree.FindNode(mapNode.Title);
if (mapNode.Title == "Teens")
{
System.Web.UI.WebControls.TreeNode parent = e.Node.Parent;
if (parent != null)
{
parent.ChildNodes.Remove(e.Node);
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeViewSM" runat="server" DataSourceID="SiteMapDataSourceSM" ShowLines="True" ExpandDepth="1" />
<asp:SiteMapDataSource ID="SiteMapDataSourceSM" runat="server" />
</div>
</form>
</body>
</html>
IronWill
Member
57 Points
138 Posts
Re: Treeview hide sitemap node...
Jun 10, 2009 01:46 AM|LINK
Could anyone who actually got this working please please PLEASE post their code from their Web.sitemap, Web.config and actual page files?!? I've tried entering in the code on this page exactly as the original poster had it with the script altered only to include the proper TreeView id number and the title of the node to be hidden, AND IT DOESN'T WORK.
Help!!!!