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

RadListBoxItemCollection Object

The RadListBoxItemCollection object is returned by the get_items method of the RadListBox client object. The following table lists the most important methods:

  

NameParametersReturn TypeDescription
addRadListBoxItemnoneAdds an item to the Items collection. (see Example 1)
insertint, RadListBoxItemnoneInserts an item into the Items collection at the position specified by the first (index) parameter. (see Example 2)
removeRadListBoxItemnoneRemoves an item from the Items collection (see Example 3)
clearnonenoneClears the Items collection of RadListBox. (see Example 4)
getItemindexRadListBoxItemGets the item from the Items collection residing at the index specified by the parameter. (see Example 5)
indexOfRadListBoxItemintGets the index of an item. (see Example 6)
removeAtintnoneRemoves the item at the specified index. (see Example 7)
get_countnoneintReturns the number of items in the Items collection. (see Example 8)
forEachhandlernoneIterates through the Items collection. (see Example 9)

Example 1: Demonstrates the usage of the add method

JavaScript
var list = $find("<%= RadListBox1.ClientID %>"); 
var items = list.get_items(); list.trackChanges();
var item = new Telerik.Web.UI.RadListBoxItem();
item.set_text("New");
item.set_value("Value");
items.add(item); 
list.commitChanges();	

 Example 2: Demonstrates the usage of the insert method

JavaScript
var list = $find("<%= RadListBox1.ClientID %>");
var items = list.get_items();
list.trackChanges();
var item = new Telerik.Web.UI.RadListBoxItem();
item.set_text("New");
item.set_value("Value");
items.insert(0, item); 
list.commitChanges();	

 Example 3: Demonstrates the usage of the remove method

JavaScript
var list = $find("<%= RadListBox1.ClientID %>");
var items = list.get_items();
var item = list.get_selectedItem();
list.trackChanges();
items.remove(item);
list.commitChanges();	

 Example 4: Demonstrates the usage of the clear method

JavaScript
var list = $find("<%= RadListBox1.ClientID %>");
var items = list.get_items(); 
items.clear();	

 Example 5: Demonstrates the usage of the getItem method

JavaScript
var list = $find("<%= RadListBox1.ClientID %>");
var items = list.get_items(); 
var firstItem = items.getItem(0);	

 Example 6: Demonstrates the usage of the indexOf method

JavaScript
var list = $find("<%= RadListBox1.ClientID %>");
var items = list.get_items(); 
var index = items.indexOf(list.get_selectedItem());	

 Example 7: Demonstrates the usage of the removeAt method

JavaScript
var list = $find("<%= RadListBox1.ClientID %>");
var items = list.get_items();
var index = items.indexOf(list.get_selectedItem()); 
items.removeAt(index);	

 Example 8: Demonstrates the usage of the get_count method

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

 Example 9: Demonstrates the usage of the forEach method

JavaScript
var list = $find("<%= RadListBox1.ClientID %>");
var items = list.get_items();
items.forEach(function (item) {
	alert(item.get_text());
});	

See Also

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