Check UnCheck All CheckBoxes in Asp.Net GridView using jQuery

  ASP.NET   Thursday, January 28, 2016   4307 | No Comments Yet!!! | Not Downloaded Yet!!! | No Demo | Pawan kumar
 Tags: Check UnCheck All CheckBoxes in Asp.Net GridView using jQuery  Check UnCheck All CheckBoxes 


Here Pawan Kumar will explain how to Check UnCheck All CheckBoxes in Asp.Net GridView using jQuery


In previous post I have explained How to avoid a form from double submission using, Set max length of MultiLine TextBox in ASP.Net, Allow only alphabets in a textbox using javascript in, jQuery, ASP.NET - How to validate the file type and file size of File Upload control on file selection using the jQuery .Change() event, Create a QR Code with a Logo in ASP.Net C#, jQuery to Check UnCheck All CheckBoxes in Repeater in Asp.Net C#, and many more articles.

Now I will explain How to Check UnCheck All CheckBoxes in Asp.Net GridView using jQuery

So follow the steps to learn Check UnCheck All CheckBoxes in Asp.Net GridView using jQuery

In this article I have explained How to check uncheck or select deselect all checkboxes on click of Select All checkbox in header in Asp.Net GridView using jQuery.

Step 1:Create a aspx web page using the below codes:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<html xmlns="">
<head id="Head1" runat="server">
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var chkAll = $('.header').click(function () {
                //Check header and item's checboxes on click of header checkbox
                chkItem.prop('checked', $(this).is(':checked'));
            var chkItem = $(".item").click(function () {
                //If any of the item's checkbox is unchecked then also uncheck header's checkbox
                chkAll.prop('checked', chkItem.filter(':not(:checked)').length == 0);
    <form id="form1" runat="server">
        <asp:GridView ID="grdEmp" runat="server" AutoGenerateColumns="False" CellPadding="4"
            ForeColor="#333333" GridLines="None">
            <AlternatingRowStyle BackColor="White" />
                        <input type="checkbox" id="chkHeader" class="header" />
                        <input type="checkbox" id="chkItems" class="item" />
                <asp:BoundField HeaderText="Employee Name" DataField="EmployeeName" />
                <asp:BoundField HeaderText="Code" DataField="EmployeeCode" />
                <asp:BoundField HeaderText="Age" DataField="Age" />
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#EFF3FB" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F5F7FB" />
            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
            <SortedDescendingCellStyle BackColor="#E9EBEF" />
            <SortedDescendingHeaderStyle BackColor="#4870BE" />

Step 2: Write the following codes in aspx code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
    protected void BindGridview()
        DataTable dt = new DataTable();
        //Add Columns to datatable
        dt.Columns.Add("EmployeeId", typeof(Int32));
        dt.Columns.Add("EmployeeName", typeof(string));
        dt.Columns.Add("EmployeeCode", typeof(string));
        dt.Columns.Add("Age", typeof(Int32));
        //Adding rows and data
        dt.Rows.Add(1, "Rahul", "EMP0001", 22);
        dt.Rows.Add(2, "Sanjay", " EMP0002", 21);
        dt.Rows.Add(3, "Raja", " EMP0003", 24);
        dt.Rows.Add(4, "Barkha", " EMP0004", 26);
        dt.Rows.Add(5, "Suman", " EMP0005", 25);
        //Bind datatable to gridview
        grdEmp.DataSource = dt;








So, In this tutorial we have learned, Check UnCheck All CheckBoxes in Asp.Net GridView using jQuery

Download Source Codes