.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> JQuery >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Check/Uncheck All Checkbox in gridview with jquery

Posted By:Rajshree       Posted Date: October 22, 2010    Points: 15    Category: JQuery    URL: http://www.dotnetspark.com  

The following code Check/Uncheck All Checkbox in gridview with jquery on clicking on parent checkbox and also unchecked parent checkbox if any of the child checkbox in unchecked and check parent checkbox if all child checkbox are selected

 var gridView1Control = document.getElementById('<%= gvPayments.ClientID %>');
    $('input:checkbox[id$=chkall]', gridView1Control).click(function (e) {
        if (this.checked) {
            $('input:checkbox[id$=cbClose]', gridView1Control).attr('checked', true);
        else {
            $('input:checkbox[id$=cbClose]', gridView1Control).removeAttr('checked');
    $('input:checkbox[id$=cbClose]', gridView1Control).click(function (e) {
        //To uncheck the header checkbox when there are no selected checkboxes in itemtemplate
        if ($('input:checkbox[id$=cbClose]:checked', gridView1Control).length == 0) {
            $('input:checkbox[id$=chkall]', gridView1Control).removeAttr('checked');
        //To check the header checkbox when there are all selected checkboxes in itemtemplate
        else if ($('input:checkbox[id$=cbClose]:checked', gridView1Control).length == $('input:checkbox[id$=cbClose]', gridView1Control).length) {
            $('input:checkbox[id$=chkall]', gridView1Control).attr('checked', true);
       else {



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend