0
<script type="text/javascript">
    $(document).ready(function () {
        //Checked or unchecked All Checkboxes inside grid with header checkbox   
        $("#<%= GridView_ManageUser.ClientID %> input[id*='checkbox_allcheckUncheck']").click(function () {
                if ($(this).is('checked'))
                    //Checkd All Child checkbox  
                    $("#<%= GridView_ManageUser.ClientID %> input[id*='CheckBox']").attr('checked', this.checked);
                else
                    //UnCheckd All Child checkbox  
                    $("#<%= GridView_ManageUser.ClientID %> input[id*='CheckBox']").removeAttr('checked', this.checked);
            });
            // Header checkbox checked or unchecked inside grid row checkboxes   
        $("#<%=GridView_ManageUser.ClientID%> input[id*='CheckBox']checkbox").click(function () {
                //Get All Checkbox inside grid  
            var GetAllCheckboxes = $("#<%=GridView_ManageUser.ClientID%> input[id*='CheckBox']checkbox").size();
                //Get number of checked checkboxes inside grid   
            var MarkcheckedCheckboxes = $("#<%=GridView_ManageUser.ClientID%> input[id*='CheckBox']checkboxchecked").size();
                //Check / Uncheck top checkbox if all the checked boxes in list are checked  
            $("#<%=GridView_ManageUser.ClientID%> input[id*='checkbox_allcheckUncheck']checkbox").attr('checked', GetAllCheckboxes == MarkcheckedCheckboxes);
            });
        });
    </script>

                        <asp:BoundField DataField="emailID" HeaderText="Email">
                            <ItemStyle Width="55%" CssClass="cssClass_hover" />
                        </asp:BoundField>
                    </Columns>
                    <PagerSettings FirstPageText="First" LastPageText="Last" Mode="NextPreviousFirstLast" />

                    <PagerStyle Height="50px" />
                    <RowStyle HorizontalAlign="Center" Height="45px"></RowStyle>
                </asp:GridView>  

trying to do checked or uncheck all checkbox within gridview . but header checkbox check changed event is not working here This is my jquery code ..i am trying to check uncheck all checkbox of gridview but failed to do

1 Answer 1

1

You can do it with simple code. Get the status of check/uncheck all status and assign that status to all checkboxes in the gridview.

    $("#<%= GridView_ManageUser.ClientID %> input[id*='checkbox_allcheckUncheck']").change(function () {
        $("#<%= GridView_ManageUser.ClientID %> input[id*='CheckBox']").prop('checked', $(this).is(':checked'));
    });

To get total number of checkboxes

var MarkcheckedCheckboxes = $("#<%=GridView_ManageUser.ClientID%> input[id*='CheckBox']").length;

To get total number of checked checkboxes

var MarkcheckedCheckboxes = $("#<%=GridView_ManageUser.ClientID%> input[id*='CheckBox']:checked").length;
Sign up to request clarification or add additional context in comments.

3 Comments

but header checkbox event is not firing
perfect.. can u please tell how to get selected checkbox count
Edited answer to get total number of checkboxes and checked number of checkboxes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.