.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Checkbox inside Gridview in asp.net

Posted By: Ramesh     Posted Date: November 12, 2008    Points:2   Category :ASP.Net
I need to put checkbox inside gridview means for each row i need to have one check box just like yahoo or gmail, and one master check box on top of gridview to select/unselect all the row inside gridview.

I am using C# in code behind any help will be appreciated

Thanks in advance.

Author: Amit Mehra             
Posted Date: November 13, 2008     Points: 5   

All you need to have Template column inside your gridview which should have checkbox and javascript function to seelect/unselect all the rows inside grid view

<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server" type="checkbox" />

For sample code please refer this article


Please "Mark As Answer " if this post help you.
Author: susant             
Posted Date: November 14, 2008     Points: 5   

Hi Ramesh check this to add each row one check Box.. and Amit code to add checkbox for Header section..
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<asp:CheckBox ID="ch1" runat="server" />

Check this Link Also: http://www.dotnetspark.com/kb/125-gridview-with-checkbox-for-deleteing-checked.aspx


Author: Suresh             
Posted Date: November 14, 2008     Points: 5   

Hi amit mehra
I got error like this,
(Error 1 The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

what to do.

Author: Amit Mehra             
Posted Date: November 14, 2008     Points: 5   

Hi Suresh,

you have to add System.Text namespace on your .cs file to access StringBuilder class for eg

using System.Text;

or give the fill name eg.


Please "Mark As Answer " if this post help you.
Author: Suresh             
Posted Date: November 14, 2008     Points: 5   

Hi Amit Mehra
Why did u give DatasourceID="mySource" in the gridview below code. can u plz explain clearly b'coz im new to asp.net.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="PersonID" DataSourceID="mySource" Width="366px" CellPadding="4" ForeColor="#333333" GridLines="None">

Thank you for ur nice reply

Author: Suresh             
Posted Date: November 15, 2008     Points: 5   

Hi amit mehra

can u please explain this javascript.How this process is flow

<script type ="text/javascript" >

function SelectAllCheckboxes(spanChk){

// Added as ASPX uses SPAN for checkbox

var oItem = spanChk.children;

var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];




if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)









Author: Amit Mehra             
Posted Date: November 16, 2008     Points: 5   

When you attach the CheckBox to DataGrid This Javascript function will be fired to add this event to the checkbox you have to say like this


Please "Mark As Answer " if this post help you.
Author: Suresh             
Posted Date: November 17, 2008     Points: 5   

Hi amith mehra
I knew that how javascript function firing. i want to how the process is flow inside the javascript.can u plz explain through command line in javascript. then only begginers can understand easily.

Author: Athira Sreejith             
Posted Date: December 31, 2008     Points: 5   


Check with this design:

<asp:TemplateField HeaderText="Approved" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
<asp:CheckBox ID="chkCheckAll" runat="server" AutoPostBack="true" EnableViewState="true"
OnCheckedChanged="chkCheckAll_CheckedChanged" />
<asp:CheckBox ID="ChkStatus" AutoPostBack="true" runat="server" Checked='<%# Bind("IsStatus") %>'
OnCheckedChanged="ChkStatus_CheckedChanged" />

Author: Clintonzz             
Posted Date: May 14, 2014     Points: 20   

Some materials towards gridview checkbox column might offer you some help:


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend