Remove/hide child nodes?

5 posts, 1 answers
  1. Megan
    Megan avatar
    56 posts
    Member since:
    Aug 2007

    Posted 24 Jun 2009 Link to this post

    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

  2. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 24 Jun 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Megan
    Megan avatar
    56 posts
    Member since:
    Aug 2007

    Posted 24 Jun 2009 Link to this post

    Thanks, that did the trick.
  5. swetha
    swetha avatar
    1 posts
    Member since:
    Feb 2012

    Posted 28 Feb 2012 Link to this post

    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>


  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 28 Feb 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017