Edit this page

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:

  

Name Parameters Return Type Description
add RadListBoxItem none Adds an item to the Items collection. (see Example 1)
insert int, RadListBoxItem none Inserts an item into the Items collection at the position specified by the first (index) parameter. (see Example 2)
remove RadListBoxItem none Removes an item from the Items collection (see Example 3)
clear none none Clears the Items collection of RadListBox. (see Example 4)
getItem index RadListBoxItem Gets the item from the Items collection residing at the index specified by the parameter. (see Example 5)
indexOf RadListBoxItem int Gets the index of an item. (see Example 6)
removeAt int none Removes the item at the specified index. (see Example 7)
get_count none int Returns the number of items in the Items collection. (see Example 8)
forEach handler none Iterates through the Items collection. (see Example 9)

Example 1: Demonstrates the usage of the add method

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

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

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

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

 Example 5: Demonstrates the usage of the getItem method

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

 Example 6: Demonstrates the usage of the indexOf method

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

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

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

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

See Also