RadMenu for ASP.NET AJAX

RadControls for ASP.NET AJAX

Using the server-side API, you can programmatically add, remove, and edit menu items.

Adding Items on page load

After simply adding a RadMenu control to your Web page, use the following server-side code to add items when the page loads:

 

Adding items dynamically

You can dynamically update the Items collection of RadMenu and RadMenuItem in response to a postback as well. Consider the following menu declaration:

CopyASPX
<telerik:RadMenu ID="RadMenu1" runat="server" Flow="Horizontal" Skin="Gray" OnItemClick="RadMenu1_ItemClick">
    <Items>
        <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Add Root Item"
            Value="R">
        </telerik:RadMenuItem>
        <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Add child Item"
            Value="C">
        </telerik:RadMenuItem>
    </Items>
</telerik:RadMenu>

The ItemClick event handler adds items dynamically at runtime in the post-back:

 

Clicking on both menu items results in the following:

RadMenu Add Items Dynamically

Removing, disabling, and enabling items

To remove a menu item in server-side code, use the Remove method of the RadMenuItemCollection object that contains it. To enable or disable a menu item, use the Enabled property of the RadMenuItem object itself. The following example demonstrates these techniques:

Consider the following menu:

CopyASPX
<telerik:RadMenu ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick">
    <Items>
        <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Delete an Item"
            Value="D">
            <Items>
                <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Child 1" />
                <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Child 2" />
                <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Child 3" />
                <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Child 4" />
            </Items>
        </telerik:RadMenuItem>
        <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Disable an Item"
            Value="E">
            <Items>
                <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Child 1" />
                <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Child 2" />
                <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Child 3" />
                <telerik:RadMenuItem runat="server" ExpandMode="ClientSide" Text="Child 4" />
            </Items>
        </telerik:RadMenuItem>
    </Items>
</telerik:RadMenu>

The ItemClick event handler deletes child items of the first root item dynamically at runtime in the post-back. It disables a clicked child item of the second root item, and enables all of its siblings:

 

See Also