Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have a checkboxlist of asp.net control with the help of checkbox above it i want to check or uncheck all the list items using jquery, how can we implement this
Posted

Try this code !!

C#
$(document).ready(function () {
           $('#checkkAll').click(
            function () {
                $("INPUT[type='checkbox']").attr('checked', $('#checkkAll').is(':checked'));
            });
       });



XML
<asp:CheckBox ID="checkkAll" runat="server" Text="Check All" /><br />
   <asp:CheckBoxList ID="cbList" runat="server">
       <asp:ListItem></asp:ListItem>
       <asp:ListItem></asp:ListItem>
   </asp:CheckBoxList>
 
Share this answer
 
Try below...

JQuery code below..

XML
<script src="jquery-1.4.2.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function()
        {
            $('.chkAll').click(function()
            {
                $("INPUT[type='checkbox']").attr('checked', $('#MychkAll').is(':checked'));

            });
       });
    </script>


Html part below..
ASP.NET
<asp:CheckBox ID="MychkAll" class="chkAll" runat="server" Text="Check All" /> 
       <asp:CheckBoxList ID="MyCbList" runat="server">
           <asp:ListItem Text="Item 1" Value="1"></asp:ListItem>
           <asp:ListItem Text="Item 2" Value="2"></asp:ListItem>
           <asp:ListItem Text="Item 3" Value="3"></asp:ListItem>
           <asp:ListItem Text="Item 4" Value="4"></asp:ListItem>
       </asp:CheckBoxList>

Hope this helps you..
 
Share this answer
 
v2
Comments
surendranew 19-Mar-13 7:50am    
solution 2 did not worked
surendranew 19-Mar-13 8:19am    
Solution1 also not worked im using Scripts/jquery-1.4.1.js
vinodkumarnie 19-Mar-13 9:15am    
Its working fine.. Can you share your source code that you tried...?
Rajnish Azad 10-Apr-13 6:01am    
not working this code
vinodkumarnie 10-Apr-13 6:28am    
We always post solutions after testing. Its working fine. I told you to share your source code. do it..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900