Posted
on Nov 5, 2009
(permalink)
| RadControls version |
RadControls for ASP.NET AJAX Q1 2009+
|
| .NET version |
2.0+
|
| Visual Studio version |
2005/2008
|
| programming language |
JavaScript
|
| browser support |
all browsers supported by RadControls for ASP.NET AJAX
|
PROJECT DESCRIPTION
The projects shows how to combine a RadListBox inside a RadComboBox Item Template to achieve multiple selection drop down.
The Text and Value of *all* selected Items are stored respectively as Text of the ComboBox and as Value of the *only* ComboBox Item. Each time an Item is selected/deselected in the ListBox, these two are updated to reflect the selection.
function onSelectedIndexChanged(sender, eventArgs) {
updateComboBox(sender);
}
function updateComboBox(listBox) {
var text = "";
var value = "";
var items = listBox.get_selectedItems();
for (var i = 0; i < items.length; i++) {
var item = items[i];
//Check whether the Item's 'selected' attribute is set to true.
if (item.get_selected()) {
text += item.get_text() + ", ";
value += item.get_value() + ", ";
}
}
text = text.substring(0, text.length - 2);
value = value.substring(0, value.length - 2);
var comboBox = $find("RadComboBox1");
//Set the text of the RadComboBox to the texts of the selected Items, separated by ','.
comboBox.set_text(text);
//Set the value of the RadComboBox to values of the selected Items, separated by ','.
comboBox.trackChanges();
comboBox.get_items().getItem(0).set_value(value);
comboBox.commitChanges();
}
Reply