New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

RadMenuItemCollection Object

The RadMenuItemCollection object is returned by the get_items method of the RadMenu object or the RadMenuItem object. The following table lists the most important methods.

Changes to the item collection made using these methods do not persist after a postback unless surrounded by a call to the trackChanges method of the menu object and the commitChanges method of the menu object.

In Mobile render mode, client-side RadMenu items are of type Telerik.Web.UI.MobileMenuItem while in the other render modes the items are of type Telerik.Web.UI.RadMenuItem.

NameParametersReturn TypeDescription
addRadMenuItemnoneAdds a child item to the collection. See Example 1.
insertint, RadMenuItemnoneInserts the item into the collection at the position defined by the first (index) parameter. See Example 2.
removeRadMenuItemnoneRemoves the specified item from the collection. See Example 3.
clearnonenoneClears the Items collection of all the child items it contains. See Example 4.
getItemintRadMenuItemReturns the item from the collection that resides at the specified index. See Example 5.
indexOfRadMenuItemintReturns the index of an item. See Example 6.
removeAtintnoneRemoves the item at the specified index. See Example 7.
get_countnoneintReturns the number of the items in the collection. See Example 8.

Example 1: Add a child item to the collection.

JavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
menu.trackChanges();
var menuItemClass = Telerik.Web.UI.RadMenuItem || Telerik.Web.UI.MobileMenuItem;
var childItem = new menuItemClass();
childItem.set_text("New");
menu.get_items().add(childItem);
menu.commitChanges();		

Example 2: Insert a child item to the collection on index 0.

JavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
menu.trackChanges();
var menuItemClass = Telerik.Web.UI.RadMenuItem || Telerik.Web.UI.MobileMenuItem;
var childItem = new menuItemClass();
childItem.set_text("New");
menu.get_items().insert(0, childItem);
menu.commitChanges();		

Example 3: Remove the first item from the collection.

JavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
var menuItem = menu.get_items().getItem(0);
menu.trackChanges();
menu.get_items().remove(menuItem);
menu.commitChanges();	

Example 4: Clear the first item's ItemCollection of all the child items it contains.

JavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
menu.trackChanges();
menu.get_items().getItem(0).get_items().clear();
menu.commitChanges();	

Example 5: Get the Menu's first item.

JavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
var rootItem1 = menu.get_items().getItem(0);		

Example 6: Get the index of the Menu's second item.

JavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
var rootItem2 = menu.get_items().getItem(1);
var index = menu.get_items().indexOf(rootItem2);		

Example 7: Remove the item at the specified index.

JavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
var item = menu.findItemByText("victim");
var items = item.get_parent().get_items();
var index = items.indexOf(item);
items.removeAt(index);		

Example 8: Get the Menu's root items and display each item's text.

JavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
var items = menu.get_items();
for (var i = 0; i < items.get_count(); i++) {
    alert(items.getItem(i).get_text());
}		

See Also

In this article
See Also
Not finding the help you need?
Contact Support