aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JQuery Select Header Checkbox When All Child Checkboxes Selected in Gridview

Sep 9, 2012

In this article I will explain how to check/uncheck or select/deselect all the checkboxes in gridview with header checkbox using JQuery in


In previous article I explained select/deselect checkboxes in gridview using JQuery and
how to select/deselect checkboxes in gridview using JavaScript and many articles relating to JavaScript and JQuery. Now I will explain how to select/deselect header checkbox when all child checkboxes selected in gridvuew using JQuery.

For that first design your aspx page like this

<html xmlns="">
<head id="Head1" runat="server">
<title>check uncheck all checkboxes in gridview using jquery</title>
<script type="text/javascript" src="">
<script type="text/javascript">
$(document).ready(function() {
$('[id$=chkHeader]').click(function() {
$("[id$=chkChild]").attr('checked', this.checked);
$("[id$=chkChild]").click(function() {
if ($('[id$=chkChild]').length == $('[id$=chkChild]:checked').length)
$('[id$=chkHeader]').attr("checked", "checked");
<form id="form1" runat="server">
<asp:GridView ID="gvUserInfo" runat="server">
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
<asp:CheckBox ID="chkHeader" runat="server" />
<asp:CheckBox ID="chkChild"  runat="server"/>
Now add following namespaces in codebehind
C# Code

using System;
using System.Data;
using System.Data.SqlClient;
After that add following code in code behind

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
// This method is used to bind gridview from database
protected void BindGridview()
SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB");
SqlCommand cmd = new SqlCommand("select TOP 10 UserName,LastName,Location from UserInformation", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
gvUserInfo.DataSource = ds;

Imports System.Data
Imports System.Data.SqlClient
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
End If
End Sub
' This method is used to bind gridview from database
Protected Sub BindGridview()
Dim con As New SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB")
Dim cmd As New SqlCommand("select TOP 10 UserName,LastName,Location from UserInformation", con)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
gvUserInfo.DataSource = ds
End Sub
End Class
Live Demo

UserName LastName Location
Mahesh Dasari Vijawada
Madhav Yemineni Nagpur
Prasanthi Donthi Chennai
SivaPrasad Yemineni Nagpur
Mahendra Dasari Guntur
Nagaraju Dasari Hyderabad
Santhosh VenuGopal Vizag

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Manoj said...

liked it..

Anonymous said...

I like your blog very much. One request I would like to make is that please try to write some post on other .Net technologies like ASP.NET MVC, Silverlight, WPF, ADO.NET Entity framework, Linq.

Unknown said...

Hello suresh i like your blog its awesome, could u please post events and delegates with real time example....Thanks:)...cheers

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.