This is a migrated thread and some comments may be shown as answers.

ClearCheckedItems on client Side

4 Answers 225 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 08 Dec 2011, 12:29 AM
Hello,

Is there a way to replicate the ClearCheckedItems() method on the client side for a radcombobox.

I am able the uncheck all check box using javascript, but if after I hit a button and code to the server code, the Checkbox are still considered checked. Also, if I clear the checked items using the javascript and select other items after, the counter will display a wrong
number of selected items

function radComboBoxLocationSelectedIndexChanged(item) {
  
resetRadComboboxWithCheckBox('<%=radComboBox1.ClientID %>');
  
}
  
function resetRadComboboxWithCheckBox(comboBoxClientId) {
  
var d = $find(comboBoxClientId);
  
d.set_text("");
  
d.clearSelection();
  
var items = d.get_items();
  
var itemsCount = items.get_count();
  
for (var itemIndex = 0; itemIndex < itemsCount; itemIndex++) {
  
var item = items.getItem(itemIndex);
  
var chk = getItemCheckBox(item);
  
if (chk != null) {
  
chk.checked = false;
  
}
  
}
  
}
  
 
  
 
  
 
  
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;
  
}
  
}
  
}


Any Ideas?

Thanks.

4 Answers, 1 is accepted

Sort by
0
Accepted
Bozhidar
Telerik team
answered on 09 Dec 2011, 09:35 AM
Hello Simon,

In order for any client changes to persist after a callback to the server, you have to use the trackChanges() and commitChanges() methods. Here's a sample javascript code for unselecting all items: 

function clearSelection(){

   
var combo = $find("<%= RadComboBox1.ClientID %>");
    combo.trackChanges();
    for (var i = 0; i < combo.get_items().get_count(); i++) {
        combo.get_items().getItem(i).set_checked(false);
    }
    combo.commitChanges();
}
All the best,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Pavan Kumar
Top achievements
Rank 1
answered on 07 Jun 2013, 12:12 PM
hello Bozhidar,

your answer is working perfectly for the first time, but from the second time
the check boxes are remains with checking...... 
0
Nencho
Telerik team
answered on 11 Jun 2013, 12:29 PM
Hello Pavan,

Would you elaborate what do you mean by "first time" and "second time"? I had performed some tests locally and you could observe the behavior at my end in this video. If you could also provide us with a video, demonstrating the problematic behavior which you currently facing, it would be very helpful.

Regards,
Nencho
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Gowtham
Top achievements
Rank 1
answered on 09 Jul 2014, 07:33 AM
Thanks , working fine
Tags
ComboBox
Asked by
Simon
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Pavan Kumar
Top achievements
Rank 1
Nencho
Telerik team
Gowtham
Top achievements
Rank 1
Share this question
or