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

RadPanelItemCollection Object

The RadPanelItemCollection object is returned by the get_items method of the RadPanelBar or RadPanelItem 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 panel bar object and the commitChanges method of the panel bar object.

 

NameParametersReturn TypeDescription
addRadPanelItemnoneAdds a child item to the end of the collection. See Example 1.
insertint,RadPanelItemnoneInserts the item into the collection at the position specified by the first (index) parameter. See Example 2.
removeRadPanelItemnoneRemoves the specified item from the collection. See Example 3.
removeAtintnoneRemoves the item at the specified index. See Example 4.
clearnonenoneClears the Items collection of all the child items it contains. See Example 5.
getItemintRadPanelItemReturns the item from the collection that resides at the specified index. See Example 6.
indexOfRadPanelItemintReturns the index of an item. See Example 7.
get_countnoneintReturns the number of the items in the collection. See Example 8.

Example 1: Add a new item and persist it after a postback.

JavaScript
	
function AddNewItem() {
    var panelbar = $find("<%= RadPanelBar1.ClientID %>");
    var panelItem = new Telerik.Web.UI.RadPanelItem();
    panelItem.set_text("New Item");
    panelbar.trackChanges();
    panelbar.get_items().add(panelItem); 
    panelbar.commitChanges();
}
	

Example 2: Insert a new item at index 0.

JavaScript
	
function InsertAtStart() {
    var panelbar = $find("<%= RadPanelBar1.ClientID %>");
    var panelItem = new Telerik.Web.UI.RadPanelItem();
    panelItem.set_text("New Item");
    panelbar.trackChanges();
    panelbar.get_items().insert(0, panelItem); 
    panelbar.commitChanges();
}
	

Example 3: Remove the item with text Paris from the Items collection.

JavaScript
	
function deleteItem() {
    var panelbar = $find("<%= RadPanelBar1.ClientID %>");
    var panelItem = panelbar.findItemByText("Paris");
    if (panelItem) {
        panelbar.trackChanges();
        panelbar.get_items().remove(panelItem);
        panelbar.commitChanges(); 
    }
}
	

Example 4: Remove the last item from Items collection.

JavaScript
		
function removeLastItem() {
    var panelbar = $find("<%= RadPanelBar1.ClientID %>");
    var items = panelbar.get_items();
    if (items.get_count() > 0) {
        panelbar.trackChanges();
        items.removeAt(items.get_count() - 1);
        panel.commitChanges();
    } 
}
	

Example 5: Clear the RadPanelBar first root item's Items collection of all child items it contains.

JavaScript
		
var panelBar = $find("<%= RadPanelBar1.ClientID %>");
panelBar.trackChanges();
panelBar.get_items().getItem(0).get_items().clear(); 

panelBar.commitChanges();
	

Example 6: Get a reference to the first root item.

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

Example 7: Get the item's index.

JavaScript
		
var panelBar = $find("<%= RadPanelBar1.ClientID %>");
var item = panelBar.findItemByText("target");
if (item) {
     var index = item.get_parent().get_items().indexOf(item); 
}
	

Example 8: Get all root items and display their text values.

JavaScript
		
var panelBar = $find("<%= RadPanelBar1.ClientID %>");
var items = panelBar.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