Telerik RadList Box Checkbox Items check all or uncheck all

Aspx page: I bound the lstLocations dynamically. So it look like as below.

Capture

<telerik:RadListBox ID=”lstLocations” runat=”server” CheckBoxes=”true” Width=”520px”
Height=”130px”>
</telerik:RadListBox>

// Select All checkbox buttons
<asp:CheckBox CssClass=”CBFull” ID=”chkSelectAll” runat=”server” Text=”Select All”
onclick=”javascript:return ToggleAllLocations(this);” />
// Add below function in javascript function



function ToggleAllLocations(checkBox) {
             //ctl00_ContentPlaceHolder1_RadDockLocFilter_C_lstLocations is a client id of radlistbox                   
            var listbox = $find("ctl00_ContentPlaceHolder1_RadDockLocFilter_C_lstLocations");

            var j = listbox.get_checkedItems().length;

            if (!document.getElementById(checkBox.id).checked) {
                for (var i = 0; i < j; i++) {
                    listbox.get_checkedItems()[0].uncheck();
                }
            }
            else {
                for (var i = 0; i < listbox.get_items().get_count(); i++) {
                    var item = listbox.getItem(i);
                    listbox.trackChanges();

                    item.set_checked(true);

                    listbox.commitChanges();

                }                                           
            }
            return true;
        }


Share