selected and unselected all check box of listbox on single button or checkbox

4 posts, 0 answers
  1. Rahul
    Rahul avatar
    39 posts
    Member since:
    Jan 2014

    Posted 12 Jan 2014 Link to this post

    Hi,
                      I have RadListbox i use the check box="true" property of List box. so i want to select and unselected all check box on single button click and single check box. Please provide sample code.
    Thanks,
    Rahul
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Jan 2014 Link to this post

    Hi Rahul,

    Please try to set the ShowCheckAll property of RadListBox to show a checkbox on clicking on that it will check/uncheck all items in the RadListBox as follows.

    ASPX:
    <telerik:RadListBox ID="RadListBox1" runat="server" CheckBoxes="true" ShowCheckAll="true">
        <Items>
            <telerik:RadListBoxItem Text="Item1" />
            <telerik:RadListBoxItem Text="Item2" />
            <telerik:RadListBoxItem Text="Item3" />
            <telerik:RadListBoxItem Text="Item4" />
        </Items>
    </telerik:RadListBox>
     
    Please try the following JavaScript to check/uncheck all items of RadListBox on Button Click.

    JavaScript:
    <script type="text/javascript">
        function OnClientClicked(sender, args) {
            var listbox = $find("<%=RadListBox1.ClientID %>");
            if (listbox.get_checkedItems().length == 0) {
                for (var i = 0; i < listbox.get_items().get_count(); i++) {
                    listbox.get_items().getItem(i).check();
                }
            }
            else {
                for (var i = 0; i < listbox.get_items().get_count(); i++) {
                    listbox.get_items().getItem(i).uncheck();
                }
            }
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rahul
    Rahul avatar
    39 posts
    Member since:
    Jan 2014

    Posted 24 Jan 2014 Link to this post

    hi shinu,
                         I wnat to checked/unchecked all checkbox inside the radlistview on button click client side. please provide solution .
    my cod is ;
    <asp:Button ID="btn_select" CssClass="btn btn-sm btn-info" runat="server" Text="Select All Checkbox" UseSubmitBehavior="false"></asp:Button>
    

    <telerik:RadListView ID="RadListView_Permission"  runat="server" AllowCustomPaging ="true"  AllowPaging="True" onitemdatabound="RadListView_Permission_ItemDataBound" >
                                                            <ItemTemplate>
                                                                 <div style="border:1px solid gray;">                                                                                                                          
                                                                         <table width="100%" >
                                                                            <tr>
                                                                                <td width="5%"></td>
                                                                                <td class="LabelWidth">
                                                                                    <div> 
                                                                                       <asp:Label ID="Label4" runat="server" Text='<%# (DataBinder.Eval(Container.DataItem, "PermissionItemName")) %>'></asp:Label>
                                                                                   </div>  
                                                                                </td>                                                                                                                          
                                                                                <td style="margin:2%width:70%;">                                                                        
                                                                                      <span style=margin:2%;width:50%text-align:left; "><asp:CheckBoxList RepeatDirection="Horizontal" AutoPostBack="false" CellPadding="5" CellSpacing="7"  RepeatLayout="Table"  ID="Listbox_Permission" runat="server" DataTextField="PermissionOperationName" DataValueField="PermissionItemOpearationId"  CssClass="checkbox-inline checkbox-list" >    </asp:CheckBoxList></span>
                                                                                                                                                          
                                                                                 </td>
                                                                            </tr>
                                                                        </table>
                                                                    </div>                                                              
                                                        </ItemTemplate>                                                   
                                                      </telerik:RadListView> 


    Thanks,
    Rahul
  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 29 Jan 2014 Link to this post

    Hello Rahul,

    In order to select all checkbox elements contained in the ListView control you could use the following approach. Attach handler to the Button's OnClientClick event and using jQuery select all checkboxes that have the ListView control as parent. There is a stackoverflow thread discussing similar functionality here.

    Give this approach a try and you should get the functionality you are looking for.

    Regards,
    Viktor Tachev
    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 UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top