Removing Menu Items and Child Menu Items

  • Thread starter Thread starter Larry Bud
  • Start date Start date
L

Larry Bud

Trying to conditionally remove menu items of the 2.0 .NET menu item
control and I'm stumped.

This removed a root level item:

Menu1.Items.Remove(Menu1.FindItem("Administration"))

But this does not remove it's child item

Menu1.Items.Remove(Menu1.FindItem("Administration/Activities"))

No errors are thrown, and FindItem *IS* finding Administration/
Activities value path. I'm using the default value path separator of
the forward slash, but the menu item still appears.

What am I doing wrong? Thx.
 
Trying to conditionally remove menu items of the 2.0 .NET menu item
control and I'm stumped.

This removed a root level item:

Menu1.Items.Remove(Menu1.FindItem("Administration"))

But this does not remove it's child item

Menu1.Items.Remove(Menu1.FindItem("Administration/Activities"))

No errors are thrown, and FindItem *IS* finding Administration/
Activities value path. I'm using the default value path separator of
the forward slash, but the menu item still appears.

What am I doing wrong? Thx.

Just a little more info:
Menu1.FindItem("Administration/Activities").Enable=false

DOES disable the menu item. So why can't I remove it?
 
Hi Larry,
Trying to conditionally remove menu items of the 2.0 .NET menu item
control and I'm stumped.

Why do you want to do this? I'd like to know, as there might be a smarter
way than "items.remove".

Jeppe Jespersen
Denmark
 
Hi Larry,


Why do you want to do this? I'd like to know, as there might be a smarter
way than "items.remove".

To hide menu items based on a User's role.

There's no "visible" property, and the Enable flag is just plain ugly.
 
To hide menu items based on a User's role.

Have you looked into the "security trimming" property on (i believe) the
SiteMapProvider?
Using this, you define in the web.config file what pages (and therefore
menuitems) are visible/accessible to which users.

It's pretty late here (in Euroland) $now, but I'll whip up an example
tomorrow if you want?

Jeppe Jespersen
Denmark
 
Hi, me again.

Check out this MSDN article. Let me know if this is what you want.
....and if the article helped :-)

Jeppe
 
Thanks, and I may switch to this, but any idea on why I can't remove a
child item?

Hmm.... tried reproducing your problem, but wasn't able to.
But have you tried something like:

Menu1.FindItem("Fish").ChildItems.Clear()
Menu1.Items.Remove(Menu1.FindItem("Fish"))

-Jeppe
 
Hi Larry,
Dont know if you have a solution yet or not but I test the Text property
of the menuitem to "" this had the effect of removing the menu entry. Hope
this help.

Cheers

Vinnie
 
try this:

MenuItem menuItemAdmin = menuMain.FindItem("Administration");
MenuItem menuItemActivities = menuMain.FindItem("Administration/Activities");
menuItemAdmin.ChildItems.Remove(menuItemActivities );
 
try this:

MenuItem menuItemAdmin = menuMain.FindItem("Administration");
MenuItem menuItemActivities = menuMain.FindItem("Administration/Activities");
menuItemAdmin.ChildItems.Remove(menuItemActivities );

Thanks, this worked!
 
Back
Top