Asp.Net: Menu control remove MenuItem (MenuItemDataBound)

by Pieter Brinkman 26. February 2009 07:58

For a project I needed to remove menu items to the pages in the folder 'Subscriberpages' when a the user is in the Role of 'Marketing' and 'AccountManagement'. To do this I added the following code to the MenuItemDataBound event.

[code:c#]
protected void mainMenu_MenuItemDataBound(object sender, MenuEventArgs e)
{
 SiteMapNode node = e.Item.DataItem as SiteMapNode;

 if (node.Url.Contains("Subscriberpages"))
 {
  if (HttpContext.Current.User.IsInRole("Marketing") || HttpContext.Current.User.IsInRole("AccountManagement'"))
  {
   // Get menu.
   Menu topMenu = (Menu)sender;


   // Remove dataitem from menu.
   topMenu.Items.Remove(e.Item);
  }
 }
}
[/code]


To generate the menu I used the Web.sitemap and the asp:Menu control.

 

Tags: , , ,

ASP.Net | Controls

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About Me

My name is Pieter Brinkman I am Solution Architect for Sitecore in The Netherlands. My interests are mainly ASP.NET, MSSQL and Content Management Systems.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

RecentComments

Comment RSS

Most comments