Removing Menu Items and Child Menu Items

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.
 
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.

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

DOES disable the menu item. So why can't I remove it?
 
J

Jeppe Jespersen

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
 
L

Larry Bud

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.
 
J

Jeppe Jespersen

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
 
J

Jeppe Jespersen

Hi, me again.

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

Jeppe
 
J

Jeppe Jespersen

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
 
G

Guest

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
 
H

hepek

try this:

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

Larry Bud

try this:

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

Thanks, this worked!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top