all things Sitecore related

Asp.Net: Menu control remove MenuItem (MenuItemDataBound)

By on February 26, 2009 in ASP.Net, Controls with 0 Comments

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.


protected void mainMenu_MenuItemDataBound(object sender, MenuEventArgs e)
{
 SiteMapNode node = e.Item.DataItem as SiteMapNode;

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

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

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

About the Author

About the Author: Pieter is Technical Marketing Manager for Sitecore Netherlands and owner of Gaatverweg.nl. He has more than ten years experience with software developing in multiple programming languages and with different Content Management Systems. Before joining Sitecore Pieter was a lead developer for multiple Sitecore and .Net projects, he joined Sitecore in 2011 as an Solution Architect in The Netherlands, after two years as an Solution Architect he joined the Technical Marketing department. In the role as Techinical Marketing Manager he is responsible for the Global MVP program and the Sitecore technical branding strategy. You can follow Pieter on twitter: @pieterbrink123 or Google+ .

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Post a Comment

Your email address will not be published. Required fields are marked *

Top