Sometimes simple things go wrong, just like this simple functionality of "Select all" took my whole day. This is also important in the clumsy world, no one has that much time to check the boxes one by one. It is okay if there are 4-5 checkboxes but what about when it comes to 100 – 200 – that's a bit time consuming, so to shorthand that here, in this article I will show you how to select and deselect all the checkboxes in GridView using jQuery in ASP.NET C#.
Initial Chamber
Step 1: Open your Visual Studio 2010 and create an Empty Website, Give a suitable name, gridview_demo.
Step 2: In Solution Explorer, you get your empty website, Add a web form, SQL Database. Here are the steps,
For Web Form:
gridview_demo (Your Empty Website) - Right Click, Add New Item, then Web Form. Name it gridview_demo.aspx.
For SQL Server Database:
gridview_demo (Your Empty Website) - Right Click, Add New Item, then SQL Server Database. Add Database inside the App_Data_folder.
Database Chamber:
Step 3:
Get to your Database [Database.mdf], we will create a table - tbl_Data, Go to the database.mdf - Table, then add New table, design your table like the following:
Table - tbl_data [Don’t forget to make ID - Identity Specification, click Yes]

Design Chamber
Step 5:
Now, open your gridview_demo.aspx file, were we create our design by taking Gridview from the toolbox, After dragging the control – add 4 bound field button – Name it as : ID, Name , Location and Select All. You have to change the “Select All field” to – “Template Field”.
Template Field:
We use Template Fields when we wish to display ASP.NET controls in a GridView column. We display ASP.NET controls in a GridView column to provide additional functionality in the user interface.
Here are some beautiful answers regarding Template Fields – Template Fields.
Gridview_demo.aspx:
- <%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>
- <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script type="text/javascript" language="javascript"> functionCheckall(Checkbox) { var GridView1 = document.getElementById("
- <%=GridView1.ClientID %>"); for (i = 1; i
- < GridView1.rows.length; i++) { GridView1.rows[i].cells[3].getElementsByTagName( "INPUT")[0].checked=C heckbox.checked; } } </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:GridViewID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
- <AlternatingRowStyleBackColor="White" />
- <Columns>
- <asp:TemplateField>
- <HeaderTemplate>
- <asp:CheckBoxID="CheckBox1" AutoPostBack="true" OnCheckedChanged="chckchanged" runat="server" /> </HeaderTemplate>
- <ItemTemplate>
- <asp:CheckBoxID="CheckBox2" runat="server" /> </ItemTemplate>
- </asp:TemplateField>
- <asp:BoundFieldDataField="id" HeaderText="ID" />
- <asp:BoundFieldDataField="name" HeaderText="Name" />
- <asp:BoundFieldDataField="location" HeaderText="Location" /> </Columns>
- <FooterStyleBackColor="#990000" Font-Bold="True" ForeColor="White" />
- <HeaderStyleBackColor="#990000" Font-Bold="True" ForeColor="White" />
- <PagerStyleBackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
- <RowStyleBackColor="#FFFBD6" ForeColor="#333333" />
- <SelectedRowStyleBackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
- <SortedAscendingCellStyleBackColor="#FDF5AC" />
- <SortedAscendingHeaderStyleBackColor="#4D0000" />
- <SortedDescendingCellStyleBackColor="#FCF6C0" />
- <SortedDescendingHeaderStyleBackColor="#820000" /> </asp:GridView>
- </div>
- </form>
- </body>
- </html>



Sridhar JohnPosted Jun 6, 2018, 7:09 AM
Very useful article...nice
Tarun SaraswatPosted May 25, 2017, 3:09 AM
No need of java script just use like <asp:CheckBox ID="Checkbox2" Checked="false" OnCheckedChanged="chckchanged" AutoPostBack="true" runat="server" /> and enjoy simple code.
Vinay SinghPosted Jun 5, 2016, 1:25 PM
Nice article
Ajeet MishraPosted Apr 28, 2016, 9:19 AM
Nice
Humayun Kabir MamunPosted Apr 17, 2016, 2:21 AM
Nice...
Debasis SahaPosted Apr 15, 2016, 12:24 AM
Nice article..
Vignesh ManiPosted Apr 14, 2016, 3:42 PM
Nice
Rahul Kumar SaxenaPosted Apr 14, 2016, 2:51 PM
Good work