Category Archives: SiteMapDataSource

SiteMapDataSource

[RESOLVED]Add current style

I’ve a repater in a Masterpage to build a menu binded to websitemap.

This i the code:

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False"/>
	        <div class="menu-search">
            <asp:Repeater runat="server" ID="menu" DataSourceID="SiteMapDataSource1">
                <HeaderTemplate>
                    <ul id="topnav">
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
                        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
                        <asp:Repeater ID="submenu" runat="server" DataSource='<%# DirectCast(Container.DataItem, SiteMapNode).ChildNodes%>'>
                            <HeaderTemplate>
                                <ul>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <li runat="server" id="idLi">
                                    <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
                                </li>
                            </ItemTemplate>
                            <FooterTemplate>
                                </ul>
                            </FooterTemplate>
                        </asp:Repeater>
                    </li>
                </ItemTemplate>
                <FooterTemplate>
                    </ul>
                </FooterTemplate>
            </asp:Repeater>
	        </div>

My problem is add "current" style to selected menu.

How I can do this?

There is a way to do this?

Using itemdatabound event?

Hi,

Check this site with similar issue with solution:

http://forums.asp.net/t/1423698.aspx/1

[RESOLVED]Maintaining treeview state across your site in a master page using Web.sitemap

Hi,

I am using a treeview for navigation and set the ExpandDepth="1" to only display the parent nodes by default which is how I would like to start off and it works great.

However, when I expand a parent node and select one of the child nodes, then I would like the treeview to maintain it’s state. How can I do that?

I saw lot’s of threads here about the same issue but as far as I can tell they are all using xps (whatever that is) instead of a Web.sitemap (which is what I’m using) as the datasourse for the treeview.

Can anyone explain to me how to maintain the treeview state across the website using Web.sitemap?

The code is:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>default</title>
    <link href="NTstyle.css" rel="stylesheet" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
        <div id="pagewrapper">
            <div id="masthead">
                <img src="Images/header_home.png" />
            </div>
            <div id="breadcrumb">
                <asp:SiteMapPath ID="SiteMapPath1" runat="server">
                </asp:SiteMapPath>
            </div>
            <div id="container">
                <div id="left_col">
                    <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" ExpandDepth="1" Height="450px" ImageSet="Arrows" Width="16px">
                        <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
                        <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
                        <ParentNodeStyle Font-Bold="False" />
                        <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" />
                    </asp:TreeView>
                    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
                </div>
                <div id="page_content">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                        <p>page_content</p>
                    </asp:ContentPlaceHolder>
                </div>
            </div>
            <div id="footer">
                For suggestions, questions, problems, contact the
		<a href=mailto:someone@somewhere.com?subject=enquiry>webmaster</a><br />
                Copyright 2014
            </div>
        </div>
    </form>
</body>
</html>

Hi,

Nebulosa

I am using a treeview for navigation and set the ExpandDepth="1" to only display the parent nodes by default which is how I would like to start off and it works great.

However, when I expand a parent node and select one of the child nodes, then I would like the treeview to maintain it’s state. How can I do that?

Firstly, It has nothing to do with web.sitemap you are using. It is the most basic problem when it comes to retaining the state of the TreeView accross multiple pages specially when using MasterPages. Now, Why this happens? It is very simple when we open
a new page the state of the treeview is lost and TreeView opens up with the original ExpandDepth set. To maintain the state of the TreeView we need to use Session object. We have to save the state of the TreeView into the Session object and use it across multiple
pages.

On, How to save the TreeViewState in Session and use it. Below are the two articles you can refer to:

Maintain ASP.NET TreeView State (CSASPNETMaintainTreeViewState) -
http://code.msdn.microsoft.com/CSASPNETMaintainTreeViewSta-c7673683

Save TreeView Nodes Expansion –
http://www.c-sharpcorner.com/uploadfile/VIMAL.LAKHERA/save-treeview-nodes-expansion/

Best Regards!

 

Hi Sam,

thanks for looking into this. However, the 2 links you provided didn’t really help.

The first one

Sam – MSFT

Maintain ASP.NET TreeView State (CSASPNETMaintainTreeViewState) -
http://code.msdn.microsoft.com/CSASPNETMaintainTreeViewSta-c7673683

uses a "save treeview state" button. I have never seen a website ask the user to click on a "save treeview state" button before. Seems a bizarre solution.

The second one

Sam – MSFT

Save TreeView Nodes Expansion –
http://www.c-sharpcorner.com/uploadfile/VIMAL.LAKHERA/save-treeview-nodes-expansion/

is too complicated for me. There are no clear instructions what I am supposed to do. I copied the full CS class code into my CSS file but that came up with lots of red underlines indicating errors. Could it be because I’m using Visual Studio Express 2012?

Anyway, I am a novice and need clearer instructions than that. Sorry for being so thick. Can you help?

Together with the help from a friend we found the solution and it works perfectly.

This is the code for my master page:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>default</title>
    <link href="NTstyle.css" rel="stylesheet" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
        <div id="pagewrapper">
            <div id="masthead">
                <asp:Image ID="Header" runat="server" ImageUrl="~/Images/header_home.png" ImageAlign="Left" />
            </div>
            <div id="breadcrumb">
                <asp:SiteMapPath ID="SiteMapPath1" runat="server">
                </asp:SiteMapPath>
            </div>
            <div id="container">
                <div id="left_col">
                    <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" ExpandDepth="1" NodeIndent="10" OnTreeNodeCollapsed="TreeView1_TreeNodeCollapsed" OnDataBound="TreeView1_DataBound" OnTreeNodeExpanded="TreeView1_TreeNodeExpanded">
                        <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
                        <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
                        <ParentNodeStyle Font-Bold="False" />
                        <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" />
                    </asp:TreeView>
                    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
                </div>
                <div id="page_content">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                        <p>page_content</p>
                    </asp:ContentPlaceHolder>
                </div>
            </div>
            <div id="footer">
                For suggestions, questions, problems, contact the webmaster<br />
                Copyright 2014
            </div>
        </div>
    </form>
</body>
</html>

And this is the CS code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        {
            //
            // Disable ExpandDepth if the TreeView's expand/collapse
            // state is stored in session.
            //
            if (Session["TreeViewState"] != null)
                TreeView1.ExpandDepth = -1;
        }
    }
    protected void TreeView1_DataBound(object sender, EventArgs e)
    {
        if (Session["TreeViewState"] == null)
        {
            //
            // Record the TreeView's current expand/collapse state.
            //
            List<string> list = new List<string>(16);
            SaveTreeViewState(TreeView1.Nodes, list);
            Session["TreeViewState"] = list;
        }
        else
        {
            //
            // Apply the recorded expand/collapse state to the TreeView.
            //
            List<string> list = (List<string>)Session["TreeViewState"];
            RestoreTreeViewState(TreeView1.Nodes, list);
        }
    }

    protected void TreeView1_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
    {
        if (IsPostBack)
        {
            List<string> list = new List<string>(16);
            SaveTreeViewState(TreeView1.Nodes, list);
            Session["TreeViewState"] = list;
        }
    }

    protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
    {
        if (IsPostBack)
        {
            List<string> list = new List<string>(16);
            SaveTreeViewState(TreeView1.Nodes, list);
            Session["TreeViewState"] = list;
        }
    }

    private void SaveTreeViewState(TreeNodeCollection nodes, List<string> list)
    {
        //
        // Recursivley record all expanded nodes in the List.
        //
        foreach (TreeNode node in nodes)
        {
            if (node.ChildNodes != null && node.ChildNodes.Count != 0)
            {
                if (node.Expanded.HasValue && node.Expanded == true && !String.IsNullOrEmpty(node.Text))
                    list.Add(node.Text);
                SaveTreeViewState(node.ChildNodes, list);
            }
        }
    }

    private void RestoreTreeViewState(TreeNodeCollection nodes, List<string> list)
    {
        foreach (TreeNode node in nodes)
        {
            //
            // Restore the state of one node.
            //
            if (list.Contains(node.Text))
            {
                if (node.ChildNodes != null && node.ChildNodes.Count != 0 && node.Expanded.HasValue && node.Expanded == false)
                    node.Expand();
            }
            else
            {
                if (node.ChildNodes != null && node.ChildNodes.Count != 0 && node.Expanded.HasValue && node.Expanded == true)
                    node.Collapse();
            }

            //
            // If the node has child nodes, restore their state, too.
            //
            if (node.ChildNodes != null && node.ChildNodes.Count != 0)
                RestoreTreeViewState(node.ChildNodes, list);
        }
    }
}

 

[RESOLVED]Vertical Menu with SiteMap

Hi everybody,

I have a menu control (dynamic) with a sitemap datasource.  It is set to vertical but the sub menu items appear to the right of the root node.

I want the menu to expand vertically.  I can hard code the position with 

DynamicVerticalOffset="X"
DynamicHorizontalOffset="-Y"

But I was wondering is there a better way.

Currently:

Menu > Sub Menu

            Sub Menu

Want:

Menu >

Sub Menu

Sub Menu

Thanks

hi,

Currently:

Menu > Sub Menu

            Sub Menu

Want:

Menu >

Sub Menu

Sub Menu

had you try to set Orientation=”Horizontal”? you can try to use Orientation property, as shown below:

 <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" ></asp:Menu>
 <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />

you can also refer to the link below:

ASP.NET Easy Menu – Build from SiteMap

http://www.obout.com/em/build_from_sitemap.aspx

Hope it helps you.

Thanks Happy,

Setting Orientation to Horizontal worked.

I had assumed "Horizontal" would result in:

Menu > Sub Menu | Sub Menu 

Thanks Again.

[RESOLVED]How to use Sitemappath control to add breadcrumbs in Master Page of a website?

I am trying to add breadcrumbs on my web pages for easy navigation. For this I am using SiteMapPath Control of Asp.Net and along with this I have also made a breadcrumb.Sitemap file which list all the pages. But While implementing the sitemappath in my master
page, I am getting a generic error. I am not able to understand why is this happening?
This is the basic structure of my aspx page-

<div id="menu-pt">
<div class="hm"><a href="Page1.aspx" class="active">Home</a></div>
<div id="nav">
<ul id="nav" name="nav">
            	<li><a href="Page2.aspx">Page2</a></li>
                <div class="saparation"></div>
                <li><a href="Page3.aspx">Page3</a></li>
                <div class="saparation"></div>
             <li> <a href="Page4.aspx">Page4</a></li>
			<div class="saparation"></div>
            <li><a href="#">Pages</a>
            <div id ="Ul2" runat="server">
                <ul id="sub-nav" >
                <li><a href="Page5.aspx">Page5</a></li>
         		<li><a href="Page6.aspx">Page6</a></li>
          		<li><a href="Page7.aspx">Page7</a></li>
          		<li><a href="Page8.aspx">Page8</a></li>
            </ul>
            </div>
             <div id ="Ul1" runat="server">
             <ul id="sub-nav" >
             
                <li><a href="Page9.aspx">Page9</a></li>
         		<li><a href="Page10.aspx">Page10</a></li>
         		<li><a href="Page11.aspx">Page11</a></li>
          		<li><a href="Page12.aspx">Page12</a></li>
          		<li><a href="Page13.aspx">Page13</a></li>
            </ul>
            </div>
                </li>          
		   </ul>
</div>
</div>

<li>Page5,6,7,8.aspx pages is for all users. And <li>Page9,10,11,12,13.aspx pages are for logged in user.
And My breadcrumb.sitemap file is-

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="Page1.aspx" title="Home"  description="Page1">
        <siteMapNode url="Page2.aspx" title="Page2"  description="Page2" />
        <siteMapNode url="Page3.aspx" title="Page3"  description="Page3" />
      <siteMapNode url="Page4.aspx" title="Page4"  description="Page4" />
      <siteMapNode url="" title="Pages"  description="">
        <siteMapNode url="Page5.aspx" title="Page5"  description="Page5" />
        <siteMapNode url="Page6.aspx" title="Page6"  description="Page6" />
        <siteMapNode url="Page7.aspx" title="Page7"  description="Page7" />
        <siteMapNode url="Page8.aspx" title="Page8"  description="Page8" />
        <siteMapNode url="Page9.aspx" title="Page9"  description="Page9" />
        <siteMapNode url="Page10.aspx" title="Page10"  description="Page10" />
        <siteMapNode url="Page11.aspx" title="Page11"  description="Page11" />
        <siteMapNode url="Page12.aspx" title="Page12"  description="Page12" />
        <siteMapNode url="Page13.aspx" title="Page13"  description="Page13" />
      </siteMapNode>
    </siteMapNode>
</siteMap>

Also I have placed a sitemappath control on my aspx page-

<asp:SiteMapPath ID="SiteMapPath1" runat="server"></asp:SiteMapPath>

Please guide me where I am doing wrong. I read few articles and it says that this much of step is enough for adding breadcrumbs on every pages of a web site.

Please Guide me where I am doing Wrong?

Hi,

For this situation, you must set the siteMapNode url property to the correct path of the the aspx page, and put it in the root of the project. For more detailed information, you could refer to the following links:

http://www.aspdotnet-suresh.com/2012/09/sitemap-navigation-control-example-in.html

http://msdn.microsoft.com/en-us/library/x20z8c51.aspx

Besides, below is a simple example for your reference:

1. Create a folder in the project named SiteMapNavigation;

2. Within the above folder create master page SitemapNavigation.Master and pages with the master page, Home.aspx, Careers.aspx, Jobs.aspx, ContactUs.aspx;

SitemapNavigation.Master:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SitemapNavigation.master.cs" Inherits="Testing.SiteMapNavigation.SitemapNavigation" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
        <div style="background-color:red">fdssdfdfdsfs</div>
                       <br />
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        <asp:TreeView ID="TreeView1" runat="server" DataSourceId="SiteMapDataSource1" />
 
        
        <asp:SiteMapPath ID="SiteMap1" runat="server"></asp:SiteMapPath><br/><br/>

        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

3. Create the Web.sitemap file:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="~/SiteMapNavigation/Home" title="Home"  description="Home Page">
    <siteMapNode url="~/SiteMapNavigation/Careers.aspx" title="Careers"  description="Careers Page" >
    <siteMapNode url="~/SiteMapNavigation/Jobs.aspx" title="Jobs"  description="Jobs Page" />
    </siteMapNode>
    <siteMapNode url="~/SiteMapNavigation/ContactUs.aspx" title="Contact"  description="ContacUs Page" />
  </siteMapNode>
</siteMap>

If the above information couldn’t help, please tell us the error message when you encounter the issue.

Regards

Hello Sir,
Thanks a lot for explaining me the whole process in detail.
Sir, I have a doubt, I want to understand that-
1. What happens If I don’t use Menu Control of asp.net in my master page.
2. What if I make my menu’s hardcoded i.e. by using <ul><li> tags. In this case will the sitemappath will work, as it reads automatically the sitemap nodes listed in Web.sitemap file.
Actually I am not using Asp.net menu control in my master page. Instead of that I have made my own menu’s using <ul><li> tags.
And one more thing you have used update panel in your example. I want to understand why you have used update panel? Does it make any change?
If it is necessary to use update panel to handle the page refresh. Then in my example where I should place it? Actually sir, I am very curious to understand these things in details.
Hope you will clear all my doubts.

Hi,

First of all, it’s my fault that I didn’t remove the unrelated codes with this issue. In order to test another issue, I added the update panel to the page and forgot to remove it.

ashish_sourav11

What happens If I don’t use Menu Control of asp.net in my master page.

If you don’t want to use the menu control or treeview control in the page, the page would not display the whole path for the user, and when the user navigate to a specific page, he only can see the navigate path not the whole website pages path. For example:

http://asp-net-example.blogspot.com/2008/10/sitemappath-example-how-to-use.html

If you make the menu’s hardcoded, then the user can see the whole pages within your site, however, he can’t browse the page by simply click on the tags. If you use the tree view or menu control, you can browse to the specific page by clicking on the corresponding node
within control, it’s really useful and simple.

Besides, the sitemapdatasource control automatically works with the application’s web.sitemap file. It allow to bind the hierarchical sitemap data with hierarchical web server control such as sitemappath, treeview, menu and so on. For detailed information,
please refer to:

http://www.codecomplete4u.com/asp-net-navigation-sitemap-part-2/

Regards

Thanks a ton Sir Smile
Thanks for explaining me everything so beautifully.
Actually Since I am using three different masterpages that is why I was getting that error.
Sir, Now what I did I only listed those pages in which my first master page was used, and I was able to implement breadcrumbs on those pages.
So, I guess I have to make three different Web.Sitemap Pages? Am I right Sir. . .?
Please clear this confusion of mine.

Hi,

 

By default, ASP.NET site navigation works with an XML file that is named Web.sitemap that describes the hierarchy of the Web site. However, you might want to use more than one site-map file or site-map
provider to describe the navigation structure of a complete Web site.

 

To configure multiple site maps for a single site, you start with a site map in the root of the application. Configure the root provider as the default site-map provider in the Web.config file. Then
link to child site maps or providers by referencing them in a
SiteMapNode
object.

 

http://msdn.microsoft.com/en-us/library/ms178426(v=vs.100).aspx

http://www.codeproject.com/Articles/26962/Using-More-than-One-SiteMapPath-in-a-Single-Web-Pr

Regards

[RESOLVED]How to collapse the tree view after the page is loaded using javascript

Hi!

Please look the below code:

<asp:TreeView ID="TreeView1" runat="server" CssClass="treeview" DataSourceID="SiteMapDataSource1" ShowLines="True" OnTreeNodeDataBound="TreeView1_TreeNodeDataBound">
</asp:TreeView>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" StartingNodeUrl="~/Modules/Reports/Report.aspx" />

My datasource for the tree view is sitemapdatasource. Now, i want the treeview be collapsed after the page is loaded.

I want to use javascript for it.

Any idea please???

hi cnsuman,

please check this thread:

http://forums.asp.net/p/1288507/2504034.aspx

hope this helps you, thanks~ 

Thank you for the suggestion

But in my case, i do not want mouseover but +/-  so that user click on + to expand and – to collapse but as a default, all subnodes should be collapsed

Did you get me please?? 

hi cnsuman,

thanks for your feedback!

according the code in the thread I post. you can modify it to meet your need.

eg.

<script type="text/javascript">
        function TreeviewExpandCollapseAll(treeViewId, expandAll) {
            var displayState = (expandAll == true ? "none" : "block");
            var treeView = document.getElementById(treeViewId);
            if (treeView) {
                var treeLinks = treeView.getElementsByTagName("a");
                var nodeCount = treeLinks.length;
                var flag = true; for (i = 0; i < nodeCount; i++) {
                    if (treeLinks[i].firstChild.tagName) {
                        if (treeLinks[i].firstChild.tagName.toLowerCase() == "img") {
                            var node = treeLinks[i];
                            var level = parseInt(treeLinks[i].id.substr(treeLinks[i].id.length - 1), 10);
                            var childContainer = GetParentByTagName("table", node).nextSibling; if (flag) {
                                if (childContainer.style.display == displayState) {
                                    TreeView_ToggleNode(eval(treeViewId + "_Data"), level, node, 'r', childContainer);
                                }
                                flag = false;
                            }
                            else {
                                if (childContainer.style.display == displayState)
                                    TreeView_ToggleNode(eval(treeViewId + "_Data"), level, node, 'l', childContainer);
                            }
                        }
                    }
                } //for loop ends
            }
        } //utility function to get the container of an element by tagname
        function GetParentByTagName(parentTagName, childElementObj) {
            var parent = childElementObj.parentNode;
            while (parent.tagName.toLowerCase() != parentTagName.toLowerCase()) {
                parent = parent.parentNode;
            }
            return parent;
        }

        function collapse() {
            TreeviewExpandCollapseAll('<%=TreeView1.ClientID%>', false);
        }
    </script>
</head>
<body onload="collapse()">
    <form runat='server'>
    <asp:TreeView ID="TreeView1" runat="server" CssClass="treeview" ....

 

Thank you Yanping,

but i couldn’t get it preperly please.

As i have published my Report_menu.ascx code before, i am getting the data from the sitemapdatasource and my report_menu.ascx.cs code is as below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using nsSecurity;

public partial class WebComp_Reports_reports_menu : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
    {
        AppSecurity oSec = new AppSecurity();
        UserInfo oUsr = ((UserInfo)Session["UserInfo"]);
        ArrayList oRights = ((ArrayList)Session["UserRights"]);

        System.Web.UI.WebControls.TreeView menu = (System.Web.UI.WebControls.TreeView)sender;
        SiteMapNode mapNode = (SiteMapNode)e.Node.DataItem;

        // Security
        if (mapNode.ResourceKey != "")
        {
            if ((!oSec.HasAccess(oRights, oUsr, mapNode.ResourceKey)) | (mapNode.ResourceKey == "0"))
            {
                e.Node.ChildNodes.Remove(e.Node);
                TreeView1.Nodes.Remove(e.Node);
                
            }
        }
        
    }
}

 

I am not sure how do i embedd your code with my one.

Plz, help me

hi cnsuman,

To place the javascript code my previous posted in the client side(.aspx)

there defined onload event to collapse the TreeView1 using javascript.

A slite addition after making an observation durring debug. I saw src attribute was undefined, and the cause was the array of image url’s needed to have some indexes initialized. See where I asign index 15 to the content of index 5 and the same with 14 and
4. This uses the javascript generated for the tree, but in my case it was

                                eval(treeViewId + "_Data").images[14] = eval(treeViewId + "_Data").images[4];
                                eval(treeViewId + "_Data").images[15] = eval(treeViewId + "_Data").images[5];

This fixed a bug in the code I couldn’t change where img.src was assigned to data.images[14]; or 15, but evaluation shoed4 and 5 had the right url’s.

                if (lineType == "l") {
                    img.src = data.images[14];
                }

FULL CODE:

    function TreeviewExpandCollapseAll(treeViewId, expandAll)
    {
        var displayState = (expandAll == true ? "none" : "block");
        var treeView = document.getElementById(treeViewId);
        if(treeView)
        {
            var treeLinks = treeView.getElementsByTagName("a");
            var nodeCount = treeLinks.length;
            var flag = true;
            for(i=0;i<nodeCount;i++)
            {
                if(treeLinks[i].firstChild.tagName)
                {
                    if(treeLinks[i].firstChild.tagName.toLowerCase() == "img")
                    {
                        var node = treeLinks[i];
                        var level = parseInt(treeLinks[i].id.substr(treeLinks[i].id.length – 1),10);
                        var childContainer = GetParentByTagName("table", node).nextSibling;
                        if(flag)
                        {
                            if(childContainer.style.display == displayState) {
                                eval(treeViewId + "_Data").images[14] = eval(treeViewId + "_Data").images[4];
                                eval(treeViewId + "_Data").images[15] = eval(treeViewId + "_Data").images[5];
                                TreeView_ToggleNode(eval(treeViewId +"_Data"),level,node,’r’,childContainer);
                            }
                            flag = false;
                        }
                        else
                        {
                            if(childContainer.style.display == displayState)
                                TreeView_ToggleNode(eval(treeViewId +"_Data"),level,node,’l’,childContainer);
                        }
                    }
                }
            }//for loop ends
        }
    }//utility function to get the container of an element by tagname
    function GetParentByTagName(parentTagName, childElementObj)
    {
        var parent = childElementObj.parentNode;
        while(parent.tagName.toLowerCase() != parentTagName.toLowerCase())
        {
            parent = parent.parentNode;
        }
        return parent;
    }

[RESOLVED]how to use asp:Menu control (Horizental) with a beautiful style ?

iin my code  ↓↓↓

<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal"></asp:Menu>

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

but style menu is ugly … i want to have beautiful style for asp:Menu  control  .

like telerik but with out use telerik component beacuase that are heavy for web .

<telerik:RadMenu ID="RadMenu1" runat="server" DataSourceID="SiteMapDataSource1" DataTextField="Title" DataValueField="Url"></telerik:RadMenu>
       <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" S

You can use Sliding Menu Using JQuery..

Hi,

Thanks for posting!

If you want to use asp.net control <asp:menu>,I think you need to set the menu css style like this:

http://msdn.microsoft.com/en-us/library/ms366731(v=vs.100).aspx

This link supplied some sample code for setting css style.

If you want to use js or jquery and css to set style,You can see this example:

http://www.codefear.com/scripts/25-free-jquery-menu-navigation/

http://sixrevisions.com/css/30_css_techniques_examples/

you can use those example and change some code.

Hope this helps!

 

[RESOLVED]Adding a QueryString to each SiteMapNode in a SiteMap

My Web application requires that each page have a QueryString with a specific Name/Value pair, whose value is generated dynamically at logon to the site. In the Page_Load event handler for each page I retrieve the value from the QueryString. At this point
I need to append the same QueryString to each of the SiteMapNodes in the SiteMap that are parents of the current node. I have attempted to loop through each of the RootNode’s children and append the QueryString but the SiteMapNodes are read only. Any ideas
on how to accomplish this?

jnickFL1

I have attempted to loop through each of the RootNode’s children and append the QueryString but the SiteMapNodes are read only

I’m assuming you would typically modify NavigateUrl property of MenuItem(if you are using Menu contol)/TreeNode(if you are using TreeView control).  Are you using SiteMapDataSource to display some sort of navigation menu in the page header?

I’m using the SiteMap to display "breadcumbs" at the top of each page. Not a Tree and not a Menu but the simple horizontal site map. I’m using the simple approach as shown in
http://msdn.microsoft.com/en-us/library/ms178425(v=vs.100).aspx, "How to: Programmatically Modify Site-Map Nodes in Memory"

Here is what I do, there is no need to loop through the Nodes:

AddHandler SiteMap.SiteMapResolve, AddressOf Me.ConstructSiteMap

Private Function ConstructSiteMap(ByVal sender As [Object], ByVal e As SiteMapResolveEventArgs) As SiteMapNode
 ' This sets the SiteMapPath, so we can add QueryStrings... otherwise the SiteMapPath will not render
 Dim currentNode As SiteMapNode
 If SiteMap.CurrentNode Is Nothing Then
  currentNode = e.Provider.FindSiteMapNode("~/default.aspx")
 Else
  currentNode = SiteMap.CurrentNode.Clone(True)
 End If
 Return currentNode
End Function