Hi Princy,
thanks, your solution is working fine, but if there are many elements in a RadComboBox it takes a lot of time to check/uncheck all.
So I tried it like this:
<asp:CheckBox runat="server" ID="cb_Checkbox1" Enabled="true" OnClick="onchkStatusAllClick_Checkbox1(this)" />
...
<script type="text/javascript">
function onchkStatusAllClick_Checkbox1(parentChk) {
var combo = $find("<%= cbo_RadComboBox1.ClientID %>");
items = combo.get_items();
var count = items.get_count();
if (parentChk.checked == true) {
for (var itemIndex = 0; itemIndex < count; itemIndex++) {
var item = items.getItem(itemIndex); var chk = getItemCheckBox(item);
if (chk != null) { chk.checked = true; }
}
combo.set_text("All items checked");
combo.get_checkedItems().length = count;
}
if (parentChk.checked == false) {
for (var itemIndex = 0; itemIndex < count; itemIndex++) {
var item = items.getItem(itemIndex); var chk = getItemCheckBox(item);
if (chk != null) { chk.checked = false; }
}
combo.set_text("Choose an item");
combo.get_checkedItems().length = 0;
}
}
function getItemCheckBox(item) {
//Get the 'div' representing the current RadComboBox Item.
var itemDiv = item.get_element();
//Get the collection of all 'input' elements in the 'div' (which are contained in the Item).
var inputs = itemDiv.getElementsByTagName("input");
for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++) {
var input = inputs[inputIndex];
//Check the type of the current 'input' element.
if (input.type == "checkbox") {
return input;
}
}
}
It works very fast setting all checkboxes in the RadComboBox to true or false. But it seems that the items are not being checked even though the checkboxes are checked.
Therefore I tried to set the length of the checked items array to 0 if all items are unchecked. Similarly I wanted to set the length of the array to the number of all elements if all items are checked. In this way it is not working.
Is there another way to check/uncheck all items that works faster or a possibility to set the number of checked items?