function ValidateGridView() {
var grid = document.getElementById('<%=GridView.ClientId=%>);
if (grid != null) {
var TargetBaseControl = grid;
//var TargetChildControl1 = "TxtGrNo";
//get all the control of the type INPUT in the base control.
var Inputs = TargetBaseControl.getElementsByTagName("input");
for (var n = 0; n < Inputs.length; ++n) {
if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkSelect', 0) >= 0) {
if (Inputs[n].checked) {
var RowId = (Inputs[n].parentNode.parentNode.parentNode).rowIndex;
var InpCtrls = grid.rows[RowId].getElementsByTagName('input');
for (var i = 0; i < InpCtrls.length; ++i) {
if (InpCtrls[i].id.indexOf('TxtGrNo', 0) >= 0 && InpCtrls[i].value == '') {
document.getElementById(InpCtrls[i].id).style.border = "1px solid red";
document.getElementById(InpCtrls[i].id).style.background = "#FFCECE";
document.getElementById(InpCtrls[i].id).focus();
alert('Plz Enter value in GRNumber...!');
return false;
}
}
}
}
}
}
Above code is used to validate any controls inside GridView.
I have implemented above code for checkbox and textbox inside gridview by finding all input controls from Gridview.
Same you cand use for "Select" controls inside gridview.