I have a gridview which has a CHECKBOX, A HIDDEN FIELD AND A TEXTBOX.
When the checkbox is checked the Hiddenfield value gets saved in a list.
I need to know the value of the textbox field for the hiddenfield value that is saved/checkbox selected
Script which saves the hiddenfield value to list on checkbox check
<script type="text/javascript">
//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.GVWDLegalHold.ClientID %>');
}
catch (err) {
TargetBaseControl = null;
}
//Get total no of checkboxes in a particular column inside the GridView.
try {
CheckBoxes = parseInt('<%= this.GVWDLegalHold.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.hdnFldSelectedValuesWDhold.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('chkSelectAddWDHold', 0) >= 0) {
Inputs[n].checked = CheckBox.checked;
//if (CheckBox.checked)
// SelectedItems.push(document.getElementById(Inputs[n].id.replace('chkSelectAdd', 'hdnFldId')).value);
if (CheckBox.checked) {
var strTempID = SelectedItems.push(document.getElementById(Inputs[n].id.replace
('chkSelectAddWDHold', 'hdnFldIdapWDHold')).value);
if (IsItemExists(strTempID) == -1) {
SelectedItems.push(strTempID);
}
}
else
DeleteItem(document.getElementById(Inputs[n].id.replace('chkSelectAddWDHold', 'hdnFldIdapWDHold')).value);
}
//Update Selected Values.
SelectedValues.value = SelectedItems.join('|');
//Reset Counter
CheckedCheckBoxes = CheckBox.checked ? CheckBoxes : 0;
}
function ChildClick(CheckBox, HCheckBox, Id) {
//Modifiy 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('chkSelectAddWDHold', 0) >= 0)
if (IsItemExists(document.getElementById(Inputs[n].id.replace('chkSelectAddWDHold', 'hdnFldIdapWDHold')).value) > -1) {
Inputs[n].checked = true;
CheckedCheckBoxes++;
}
else
Inputs[n].checked = false;
else if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkSelectAllWDHold', 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;
}
</script>
Aucun commentaire:
Enregistrer un commentaire