Wednesday, August 7, 2013

Checkuncheck checkbox in gridview

<script language="javascript" type="text/javascript">

var TotalChkBx;

var Counter;

window.onload = function () {

//Get total no. of CheckBoxes in side the GridView.

TotalChkBx = parseInt('<%= this.grdProdct.Rows.Count %>');

//Get total no. of checked CheckBoxes in side the GridView.



Counter = 0;

}

function HeaderClick(CheckBox) {

var TargetBaseControl;

TargetBaseControl = document.getElementById('<%= this.grdProdct.ClientID %>');

var TargetChildControl = "chkProduct";

var Inputs = TargetBaseControl.getElementsByTagName("input");

for (var n = 0; n < Inputs.length; ++n)

if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)



Inputs[n].checked = CheckBox.checked;

Counter = CheckBox.checked ? TotalChkBx : 0;

}

function confirmMsg(frm) {

var TargetBaseControl;

TargetBaseControl = document.getElementById('<%= this.grdProdct.ClientID %>');

var TargetChildControl = "chkProduct";

var Inputs = TargetBaseControl.getElementsByTagName("input");

var p = 0;

for (var n = 0; n < Inputs.length; ++n) {

if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)

if (Inputs[n].checked) { p = 1; }



}

if (p == 0) { alert('Please select product'); return false; } else return true;



}

function checkuncheck(frm) {

var TargetBaseControl;

var MainControl = document.getElementById('<%= this.chkSelectAll.ClientID %>');

TargetBaseControl = document.getElementById('<%= this.grdProdct.ClientID %>');

var TargetChildControl = "chkProduct";

var TargetChildControl = "chkProduct"

var Inputs = TargetBaseControl.getElementsByTagName("input");

var p = 0;

var p1 = 1;

for (var n = 0; n < Inputs.length; ++n) {

if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)

if (Inputs[n].checked) { p = 1; } else {p1 = 0;}



}

if (p1 == 0) { MainControl.checked = false; } else MainControl.checked = true; ;



}

</script>

No comments:

Post a Comment