ClearCheckedItems on client Side

5 posts, 1 answers
  1. Simon
    Simon avatar
    1 posts
    Member since:
    Feb 2011

    Posted 07 Dec 2011 Link to this post

    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.
  2. Answer
    Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 09 Dec 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Pavan Kumar
    Pavan Kumar avatar
    2 posts
    Member since:
    Sep 2012

    Posted 07 Jun 2013 Link to this post

    hello Bozhidar,

    your answer is working perfectly for the first time, but from the second time
    the check boxes are remains with checking...... 
  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 11 Jun 2013 Link to this post

    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.
  6. Gowtham
    Gowtham avatar
    7 posts
    Member since:
    Jun 2013

    Posted 09 Jul 2014 in reply to Bozhidar Link to this post

    Thanks , working fine
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017