This is a migrated thread and some comments may be shown as answers.

Remove/hide child nodes?

4 Answers 187 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Megan
Top achievements
Rank 1
Megan asked on 24 Jun 2009, 09:08 AM

I have a project with 2 types of users. I want only the Supervisors to be able to view the "User Management" page. This page is a child node of my rad menu and it seems that I can only hide the title node or I get this error:

"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

How do I hide just some of the pages in the child nodes?


    <siteMapNode title="Users" roles="Supervisor" target="_blank">
        <siteMapNode url="UsersOnline.aspx" title="Users Online" target="_blank" />
        <siteMapNode url="UserManagement.aspx" title="User Management" target="_blank" />
    </siteMapNode>

    Protected Sub RadMenu1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadMenu1.ItemDataBound
        Dim node As SiteMapNode = TryCast(e.Item.DataItem, SiteMapNode)

        If Not String.IsNullOrEmpty(node("target")) Then
            e.Item.Target = node("target")
        End If
        If e.Item.Text = "User Management" AndAlso msUserType = "Standard" Then
            RadMenu1.Items.Remove(e.Item)
        End If
    End Sub

4 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 24 Jun 2009, 10:56 AM
Hi Megan,

Most probably you are trying to remove child items which do not belong to the Items collection of the menu. To properly remove such items please use this code:

e.Item.Owner.Items.Remove(e.Item)

Best wishes,
Albert
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Megan
Top achievements
Rank 1
answered on 24 Jun 2009, 11:27 AM
Thanks, that did the trick.
0
swetha
Top achievements
Rank 1
answered on 28 Feb 2012, 01:44 PM
Hi,

i am using rad menu control in my application...here i am adding 4 items to the control..in aspx.cs page dynamically i need to remove item 3 and 4 for that i wrote

RadContextMenu1.Items.RemoveAt(3);

RadContextMenu1.Items.RemoveAt(4);

but it showing error " Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index "...
can u please help for this

<telerikRadContextMenu ID="RadContextMenu1" runat="server" OnClientItemClicked="ValueSelected"  

EnableScreenBoundaryDetection="true" Visible="true">
<Targets>
<telerik:ContextMenuElementTarget ElementID="btnPermission" />
</Targets>
<Items>
<telerik:RadMenuItem Text="xxt" Value="1" />
<telerik:RadMenuItem Text="xxfffffffffft" Value="2" />
<telerik:RadMenuItem Text="yyy" Value="3" />
<telerik:RadMenuItem Text="zzzzr" Value="4" />
</Items>
</telerik:RadContextMenu>


0
Princy
Top achievements
Rank 2
answered on 29 Feb 2012, 05:11 AM
Hello,

The index of RadContextMenu starts from zero. Try setting the index of RadMenuItem as follows.
C#:
RadContextMenu1.Items.RemoveAt(2);
RadContextMenu1.Items.RemoveAt(3);

Thanks,
Princy.
Tags
Menu
Asked by
Megan
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Megan
Top achievements
Rank 1
swetha
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or