Use this javascript function in gridview for select and deselect checkbox
function chkType(chk, grd) {
var mainChk;
// alert (grd);
// alert(document.getElementById("ctl00_ContentPlaceHolder1_"+grd+"_ctl01_"+chk));
if (document.getElementById("ctl00_ContentPlaceHolder1_" + grd + "_ctl01_" + chk) == null) {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + grd + "_ctl02_" + chk);
}
else {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + grd + "_ctl01_" + chk);
}
//if(document.getElementById("ctl00_ContentPlaceHolder1_"+grd+"_ctl01_"+chk).checked==true)
if (mainChk.checked == true) {
SelectAll(grd);
}
else {
Deselect(grd);
// var id=document.getElementById("ctl00_ContentPlaceHolder1_GrdAccountType_ctl01_chkAll");
// id.checked = false;
}
}
function SelectAll(Grd) {
var i;
var count = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd).rows.length;
for (i = 2; i <= count; i++) {
if (i < 10) { var id = "ctl00_ContentPlaceHolder1_" + Grd + "_ctl0" + i + "_ChkSelect"; }
else { var id = "ctl00_ContentPlaceHolder1_" + Grd + "_ctl" + i + "_ChkSelect"; }
var elem = document.getElementById(id);
try {
elem.checked = true;
;
}
catch (err) { }
}
var mainChk;
if (document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl01_chkAll") == null) {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl02_chkAll");
}
else {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl01_chkAll");
}
mainChk.checked = true;
}
function Deselect(Grd) {
var i;
var count = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd).rows.length;
for (i = 2; i <= count; i++) {
if (i < 10) {
var id = "ctl00_ContentPlaceHolder1_" + Grd + "_ctl0" + i + "_ChkSelect";
}
else {
var id = "ctl00_ContentPlaceHolder1_" + Grd + "_ctl" + i + "_ChkSelect";
}
try {
var elem = document.getElementById(id);
elem.checked = false;
}
catch (err) {
}
}
var mainChk;
if (document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl01_chkAll") == null) {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl02_chkAll");
}
else {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl01_chkAll");
}
//if(document.getElementById("ctl00_ContentPlaceHolder1_"+grd+"_ctl01_"+chk).checked==true)
mainChk.checked = false;
}
function chkType(chk, grd) {
var mainChk;
// alert (grd);
// alert(document.getElementById("ctl00_ContentPlaceHolder1_"+grd+"_ctl01_"+chk));
if (document.getElementById("ctl00_ContentPlaceHolder1_" + grd + "_ctl01_" + chk) == null) {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + grd + "_ctl02_" + chk);
}
else {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + grd + "_ctl01_" + chk);
}
//if(document.getElementById("ctl00_ContentPlaceHolder1_"+grd+"_ctl01_"+chk).checked==true)
if (mainChk.checked == true) {
SelectAll(grd);
}
else {
Deselect(grd);
// var id=document.getElementById("ctl00_ContentPlaceHolder1_GrdAccountType_ctl01_chkAll");
// id.checked = false;
}
}
function SelectAll(Grd) {
var i;
var count = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd).rows.length;
for (i = 2; i <= count; i++) {
if (i < 10) { var id = "ctl00_ContentPlaceHolder1_" + Grd + "_ctl0" + i + "_ChkSelect"; }
else { var id = "ctl00_ContentPlaceHolder1_" + Grd + "_ctl" + i + "_ChkSelect"; }
var elem = document.getElementById(id);
try {
elem.checked = true;
;
}
catch (err) { }
}
var mainChk;
if (document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl01_chkAll") == null) {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl02_chkAll");
}
else {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl01_chkAll");
}
mainChk.checked = true;
}
function Deselect(Grd) {
var i;
var count = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd).rows.length;
for (i = 2; i <= count; i++) {
if (i < 10) {
var id = "ctl00_ContentPlaceHolder1_" + Grd + "_ctl0" + i + "_ChkSelect";
}
else {
var id = "ctl00_ContentPlaceHolder1_" + Grd + "_ctl" + i + "_ChkSelect";
}
try {
var elem = document.getElementById(id);
elem.checked = false;
}
catch (err) {
}
}
var mainChk;
if (document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl01_chkAll") == null) {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl02_chkAll");
}
else {
mainChk = document.getElementById("ctl00_ContentPlaceHolder1_" + Grd + "_ctl01_chkAll");
}
//if(document.getElementById("ctl00_ContentPlaceHolder1_"+grd+"_ctl01_"+chk).checked==true)
mainChk.checked = false;
}
No comments:
Post a Comment