Check/Uncheck All Checkboxes in Asp.Net Gridview



In this article we will see how to check and uncheck all checkboxes presents in gridview control of


While programming so many times we need to take a checkbox control in gridview for allowing selection of particular row of gridview. In some cases our gridview contain 100 of records and if user wants to select all rows of gridview selecting row one by one is very tedious and time taking job for making easier this job we will see how to write simple method for selecting all checkboxes in gridview. Take a look at following snippets.

1)      Create one new website. On default.aspx page keep the gridview control with AutogeneratedColumn =false. Source for gridview look like bellow.

asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False”>


<asp:TemplateField ShowHeader=”false”>


<asp:CheckBox ID=”chkid” runat=”server” />



<asp:BoundField DataField=”Auth_Name” HeaderText=”Author Name” />

<asp:BoundField DataField=”Auth_Loc” HeaderText=”Location” />



2)      Keep two buttons on form one for checking all checkboxes and second for unchecking.

3)      The CheckState method for performing check/uncheck operation in gridview. This method will take true/false as input to check/uncheck the checkboxes of gridview.

private void CheckState(bool p)



foreach (GridViewRow row in GridView1.Rows)


CheckBox chkcheck = (CheckBox)row.FindControl(“chkid”);

chkcheck.Checked = p;



4)      Bind your gridview and run.


By using simple method we are able to check/uncheck 100 of rows also in gridview.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s