// javascript block
function SelectAll() {
var gv = document.getElementById('<%=gv_orderdetails.ClientID%>');
if (gv.rows[0].cells[5].getElementsByTagName("INPUT")[0].checked == true) {
for (var i = 1 ; i < gv.rows.length; i++) {
gv.rows[i].cells[5].getElementsByTagName("INPUT")[0].checked = true;
}
}
else {
for (var i = 1 ; i < gv.rows.length; i++) {
gv.rows[i].cells[5].getElementsByTagName("INPUT")[0].checked = false;
}
}
}
function disselect()
{
var gv = document.getElementById('<%=gv_orderdetails.ClientID%>');
var x = false;
for (var i = 1 ; i < gv.rows.length-1; i++)
{
if (gv.rows[i].cells[5].getElementsByTagName("INPUT")[0].checked == true)
{
x = true;
}
if (gv.rows[i].cells[5].getElementsByTagName("INPUT")[0].checked == false)
{
x = false;
break;
}
}
if (!x)
{
gv.rows[0].cells[5].getElementsByTagName("INPUT")[0].checked = false;
}
else
{
gv.rows[0].cells[5].getElementsByTagName("INPUT")[0].checked = true;
}
}
------------------------------------------------------------------
// In Design
<asp:TemplateField HeaderStyle-Width="30px">
<HeaderTemplate>
<asp:CheckBox ID="chk_Headerselect" runat="server" onclick="Javascript:SelectAll();" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk_select" runat="server"
onclick="Javascript:disselect();"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>