<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
%>
<! 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 >
<title>Check all checkbox in GridView</title>
< script type ="text/javascript" >
function CheckAll(chk_all)
{
var gridView = document.getElementById( " <%=GridView1.ClientID %> " );
for (i = 1 ;i < gridView.rows.length; i ++ )
{
gridView.rows[i].cells[ 0 ].children [ 0 ].checked = chk_all.checked;
}
}
</ script >
</ head >
< body >
< form id ="form1" runat ="server" >
<div style="width:100%">
< asp:GridView ID ="gv_users" runat ="server" AutoGenerateColumns ="false" >
< HeaderStyle />
< Columns >
< asp:TemplateField >
< HeaderTemplate >
< input id ="chk_all" type ="checkbox" onclick ="CheckAll(this)" runat ="server" />
</ HeaderTemplate >
< ItemTemplate >
< asp:CheckBox ID ="chk_item" runat ="server" />
</ ItemTemplate >
</ asp:TemplateField >
< asp:BoundField DataField ="ID" HeaderText ="ID" />
< asp:BoundField DataField ="Name" HeaderText ="Name" />
</ Columns >
</ asp:GridView >
</div>
</ form >
</ body >
</ html >
<! 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 >
<title>Check all checkbox in GridView</title>
< script type ="text/javascript" >
function CheckAll(chk_all)
{
var gridView = document.getElementById( " <%=GridView1.ClientID %> " );
for (i = 1 ;i < gridView.rows.length; i ++ )
{
gridView.rows[i].cells[ 0 ].children [ 0 ].checked = chk_all.checked;
}
}
</ script >
</ head >
< body >
< form id ="form1" runat ="server" >
<div style="width:100%">
< asp:GridView ID ="gv_users" runat ="server" AutoGenerateColumns ="false" >
< HeaderStyle />
< Columns >
< asp:TemplateField >
< HeaderTemplate >
< input id ="chk_all" type ="checkbox" onclick ="CheckAll(this)" runat ="server" />
</ HeaderTemplate >
< ItemTemplate >
< asp:CheckBox ID ="chk_item" runat ="server" />
</ ItemTemplate >
</ asp:TemplateField >
< asp:BoundField DataField ="ID" HeaderText ="ID" />
< asp:BoundField DataField ="Name" HeaderText ="Name" />
</ Columns >
</ asp:GridView >
</div>
</ form >
</ body >
</ html >