//Reference of the GridView. var TargetBaseControl = null; //Total no of checkboxes in a particular column inside the GridView. var CheckBoxes; //Total no of checked checkboxes in a particular column inside the GridView. var CheckedCheckBoxes; //Array of selected item's Ids. var SelectedItems; //Hidden field that wil contain string of selected item's Ids separated by '|'. var SelectedValues; window.onload = function() { //Get reference of the GridView. try { TargetBaseControl = document.getElementById('<%= this.gvAllClients.ClientID %>'); } catch(err) { TargetBaseControl = null; } //Get total no of checkboxes in a particular column inside the GridView. try { CheckBoxes = parseInt('<%= this.gvAllClients.Rows.Count %>'); } catch(err) { CheckBoxes = 0; } //Get total no of checked checkboxes in a particular column inside the GridView. CheckedCheckBoxes = 0; //Get hidden field that wil contain string of selected item's Ids separated by '|'. SelectedValues = document.getElementById('<%= this.hdnFldSelectedValues.ClientID %>'); //Get an array of selected item's Ids. if(SelectedValues.value == '') SelectedItems = new Array(); else SelectedItems = SelectedValues.value.split('|'); //Restore selected CheckBoxes' states. if(TargetBaseControl != null) RestoreState(); } ////////////////////////////////////////////////////////////////////////// function HeaderClick(CheckBox) { //Get all the control of the type INPUT in the base control. var Inputs = TargetBaseControl.getElementsByTagName('input'); //Checked/Unchecked all the checkBoxes in side the GridView & modify selected items array. for(var n = 0; n < Inputs.length; ++n) if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('',0) >= 0) { Inputs[n].checked = CheckBox.checked; if(CheckBox.checked) SelectedItems.push(document.getElementById(Inputs[n].id.replace('chkEmail_Single','hdnFldId')).value); else DeleteItem(document.getElementById(Inputs[n].id.replace('chkEmail_Single','hdnFldId')).value); } //Update Selected Values. SelectedValues.value = SelectedItems.join('|'); //Reset Counter CheckedCheckBoxes = CheckBox.checked ? CheckBoxes : 0; } ////////////////////////////////////////////////////////////////////// function ChildClick(CheckBox, HCheckBox, Id) { //Modify Counter; if(CheckBox.checked && CheckedCheckBoxes < CheckBoxes) CheckedCheckBoxes++; else if(CheckedCheckBoxes > 0) CheckedCheckBoxes--; //Change state of the header CheckBox. if(CheckedCheckBoxes < CheckBoxes) HCheckBox.checked = false; else if(CheckedCheckBoxes == CheckBoxes) HCheckBox.checked = true; //Modify selected items array. if(CheckBox.checked) SelectedItems.push(Id); else DeleteItem(Id); //Update Selected Values. SelectedValues.value = SelectedItems.join('|'); } ///////////////////////////////////////////////////////////////////////// function RestoreState() { //Get all the control of the type INPUT in the base control. var Inputs = TargetBaseControl.getElementsByTagName('input'); //Header CheckBox var HCheckBox = null; //Restore previous state of the all checkBoxes in side the GridView. for(var n = 0; n < Inputs.length; ++n) if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkEmail_Single',0) >= 0) if(IsItemExists(document.getElementById(Inputs[n].id.replace ('chkEmail_Single','hdnFldId')).value) > -1) { Inputs[n].checked = true; CheckedCheckBoxes++; } else Inputs[n].checked = false; else if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkAll',0) >= 0) HCheckBox = Inputs[n]; //Change state of the header CheckBox. if(CheckedCheckBoxes < CheckBoxes) HCheckBox.checked = false; else if(CheckedCheckBoxes == CheckBoxes) HCheckBox.checked = true; } /////////////////////////////////////////////////////////////////////////////// function DeleteItem(Text) { var n = IsItemExists(Text); if( n > -1) SelectedItems.splice(n,1); } function IsItemExists(Text) { for(var n = 0; n < SelectedItems.length; ++n) if(SelectedItems[n] == Text) return n; return -1; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)