Current location: Hot Scripts Forums » Programming Languages » ASP.NET » Using ASP.net Menu Control with a sitemap.


Using ASP.net Menu Control with a sitemap.

Reply
  #1 (permalink)  
Old 10-25-10, 02:36 AM
edson1314 edson1314 is offline
Newbie Coder
 
Join Date: Oct 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Using ASP.net Menu Control with a sitemap.

I have following sitemap defined:
PHP Code:

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

  <
siteMapNode url="" title="Root" roles="*">
    <
siteMapNode url="~/Default.aspx" title="Home" roles="*" />
    <
siteMapNode url="~/ProjectList.aspx" title="Projects" roles="*">
      <
siteMapNode url="~/ProjectOverview.aspx" title="Project Overview"  roles="*" />
      <
siteMapNode url="~/ProjectViewCalls.aspx" title="View Calls" roles="*" />
    </
siteMapNode>
    <
siteMapNode url="~/Configuration.aspx" title="Configuration" roles="Administrator" />
    <
siteMapNode url="~/YourAccount.aspx" title="Your Account" roles="Administrator" />
    <
siteMapNode url="~/Logout.aspx" title="Logout" roles="*" />
  </
siteMapNode>
</
siteMap


I have following sitemap defined:

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="Root" roles="*">
<siteMapNode url="~/Default.aspx" title="Home" roles="*" />
<siteMapNode url="~/ProjectList.aspx" title="Projects" roles="*">
<siteMapNode url="~/ProjectOverview.aspx" title="Project Overview" roles="*" />
<siteMapNode url="~/ProjectViewCalls.aspx" title="View Calls" roles="*" />
</siteMapNode>
<siteMapNode url="~/Configuration.aspx" title="Configuration" roles="Administrator" />
<siteMapNode url="~/YourAccount.aspx" title="Your Account" roles="Administrator" />
<siteMapNode url="~/Logout.aspx" title="Logout" roles="*" />
</siteMapNode>
</siteMap>

I need this to display in my menu control as: Home | Projects | Configuration | Your Account | Logout.

This is working correctly however when i navigate to the pages ProjectOverview and ProjectViewCalls, I lose the selected class="level1 selected" attribute of the list item. I want to be able to indicate what area of the site the user is currently in.

Is this possible?
Reply With Quote
  #2 (permalink)  
Old 10-25-10, 09:06 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Hi,

You could use the MenuItemDataBound method for this. :

VB.Net

Code:
Protected Sub Menu1_MenuItemDataBound1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemDataBound
        If SiteMap.CurrentNode IsNot Nothing Then
            If e.Item.Text = SiteMap.CurrentNode.Title Then
                e.Item.Selected = True
            End If
        End If
    End Sub
or C#

Code:
protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
{
    if (SiteMap.CurrentNode != null)
    {
        if (e.Item.Text == SiteMap.CurrentNode.Title)
        {
            e.Item.Selected = true;
        }
    }
}
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #3 (permalink)  
Old 10-26-10, 04:34 AM
edson1314 edson1314 is offline
Newbie Coder
 
Join Date: Oct 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
talent,learned
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Superfish jquery menu problems with modification transcend2005 CSS 2 03-25-09 01:30 AM
css problem with the scroll bar crazy.works CSS 0 11-04-08 05:34 PM
AnyLink Drop Down Menu - Smarty Error? shadyy510 JavaScript 2 05-08-08 11:44 AM
Xml / Dom / Css Mark_SC.SE JavaScript 0 06-29-05 08:05 AM


All times are GMT -5. The time now is 02:46 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.