---
title: "How to Select all checkbox in griedview in asp.net?"  
description: "//default.aspx//First step:Take a grid view and checkbox            AutoGenerateColumns=\"False\" Style=\"margin-top: 2px; margin-left: 0px; margin-botto"  
author: "gautam sen"  
published: 2014-04-18  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/663/how-to-select-all-checkbox-in-griedview-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# How to Select all checkbox in griedview in asp.net?

//default.aspx//First step:Take a [grid view](https://www.mindstick.com/articles/893/data-bound-with-grid-view-in-c-sharp-dot-net) and [checkbox](https://www.mindstick.com/articles/291/how-should-use-checkbox-control-in-vb-dot-net) <asp:[GridView](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) ID="GridView1" runat="server" Height="131px" Width="500px" DataKeyNames="Id" AutoGenerateColumns="False" Style="margin-top: 2px; margin-left: 0px; margin-bottom: 1px;"> <Columns> <asp:TemplateField HeaderText="Action"> <[ItemTemplate](https://www.mindstick.com/forum/2057/access-textbox-in-itemtemplate)> <asp:CheckBox ID="chkRow" runat="server" /> </ItemTemplate> </asp:TemplateField> </columns>\
\
//default.cs//second step:take a button for select all checkbox //[double click](https://www.mindstick.com/forum/155692/what-is-dfp-double-click-for-publisher) on button and write codeprotected void Button2_Click(object sender, EventArgs e) { CheckState(b);//this is [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) }//make [global variable](https://www.mindstick.com/interview/1856/what-is-the-difference-between-a-local-and-a-global-variable) bool b=true;//make a function [private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) void CheckState(bool p) { [foreach](https://www.mindstick.com/forum/33870/how-parallel-foreach-works-internally) (GridViewRow row in GridView1.Rows) { CheckBox chkcheck = (CheckBox)row.FindControl("chkRow"); chkcheck.Checked = p; } }

---

Original Source: https://www.mindstick.com/blog/663/how-to-select-all-checkbox-in-griedview-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
