How to select and deselect checkbox field into the GridView

Posted by SAMIR BHOGAYTA on Samir ASP.NET with C# Technology See other posts from Samir ASP.NET with C# Technology or by SAMIR BHOGAYTA
Published on 2010-02-09T21:58:00.000-08:00 Indexed on 2010/12/06 17:00 UTC
Read the original article Hit count: 338

//JavaScript function for Select and Deselect checkbox field in GridView

function SelectDeselectAll(chkAll)
{
var a = document.forms[0];
var i=0;
for(i=0;i lessthansign a.length;i++)
{
if(a[i].name.indexOf("chkItem") != -1)
{
a[i].checked = chkAll.checked;
}
}
}
function DeselectChkAll(chk)
{
var c=0;
var d=1;
var a = document.forms[0];
//alert(a.length);
if(chk.checked == false)
{
document.getElementById("chkAll").checked = chk.checked;
}
else
{

for(i=0;i lessthansign a.length;i++)
{
if(a[i].name.indexOf("chkItem") != -1)
{
if(a[i].checked==true)
{
c=1;
}
else
{
d=0;
}
}
}

if(d != 0)
{

document.getElementById("chkAll").checked =true;
}
}
}

//How to use this function

asp:TemplateField>
input id="Checkbox1" runat="server" onclick="javascript:SelectDeselectAll(this);" type="checkbox" />
/HeaderTemplate>
/asp:GridView> columns>
asp:TemplateField>headertemplate>
input id="chkAll" runat="server" onclick="javascript:SelectDeselectAll(this);" type="checkbox" />
/HeaderTemplate>


© Samir ASP.NET with C# Technology or respective owner

Related posts about How to select and deselec