Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have a check box and checkboxlist controls of asp.net when i checked the checkbox i have to select all the list items of checkboxlist using jquery, please help i have written following code but this was not working at all, i was using jquery 1.5.0

JavaScript
$(document).ready(function () {
           $("#CheckBox1").click(function () {
               $("#CheckBoxList1 input[type=checkbox]").prop('checked', true);

           });


       });
[Edit]Code block added[/Edit]
Posted
Updated 2-Apr-13 0:44am
v5

Hi Surendra. Please try this code. It would check all the check-boxes in the page that are available


C#
$(document).ready(function () {
    $("#CheckBox1").click(function () {
        if ( $(this).is(':checked'))
        {
            //alert("Checked");
            $(':checkbox').attr('checked', true);
        }
        else
        {
            //alert("Not Checked");
            $(':checkbox').attr('checked', false);
        }
    });
});


Thank you
Vamsi
 
Share this answer
 
v2
Try below..
Script part
JavaScript
<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..
HTML
<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>
 
Share this answer
 

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