CS PAGE Coding
protected void grdBatchCreation_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtPageFrom = e.Row.FindControl("txtFrom") as TextBox;
TextBox txtPageTo = e.Row.FindControl("txtTo") as TextBox;
TextBox txtTotalPageNo = e.Row.FindControl("lblNoofCase") as TextBox;
HiddenField txtRefVal = e.Row.FindControl("txtRefDOC") as HiddenField;
CheckBox chkbx = e.Row.FindControl("chkgrd") as CheckBox;
txtPageTo.Attributes.Add("onblur", "if (CheckValidPageNo('" + txtPageFrom.ClientID + "','" + txtPageTo.ClientID + "','" + txtRefVal.ClientID + "')) {return CalTotalPage('" + txtPageFrom.ClientID + "','" + txtPageTo.ClientID + "','" + txtTotalPageNo.ClientID + "'); }");
}
}
JS To Find the Row
function whichRow(obj) {
var par = obj.parentNode;
while (par.nodeName.toLowerCase() != 'tr') {
par = par.parentNode;
}
return (par.rowIndex);
}
JS for GridView validation
function CheckValidPageNo(txtFrom, txtTo, txtRefVal) {
//debugger;
///alert(txtFrom);
var grdElement = document.getElementById('<%=grdBatchCreation.ClientID%>');
var objFrom = document.getElementById(txtFrom);
var objTo = document.getElementById(txtTo);
var CurrentRefObj = document.getElementById(txtRefVal);
if (objFrom != null && CurrentRefObj != null && objTo != null) {
if (trim(objFrom.value) != "" && trim(CurrentRefObj.value) != "" && trim(objTo.value) != "") {
var CurrentFrmValue = (objFrom.value * 1);
var CurrentToValue = (objTo.value * 1);
var FromValue;
var ToValue;
var IsValid = true;
var IsFromValid = true;
var IsToValid = true;
var CurrentRefValue;
var RefValue;
var idx = whichRow(objFrom);
var rowsLength = grdElement.rows.length;
for (var i = 1; i <= rowsLength - 1; i++) {
var row = grdElement.rows[i];
//alert(row.cells[i].innerText);
//alert(row.cells[i].innerHTML);
if (row.cells[1].childNodes[0].checked && i != idx) {
CurrentRefValue = trim(CurrentRefObj.value);
RefValue = trim(row.cells[6].childNodes[0].value);
if (RefValue.toLowerCase() == CurrentRefValue.toLowerCase()) {
if (row.cells[4].childNodes[0].value != '')
FromValue = (row.cells[4].childNodes[0].value * 1);
if (row.cells[5].childNodes[0].value != '')
ToValue = (row.cells[5].childNodes[0].value * 1);
// 4 5 4 10
if (CurrentFrmValue >= FromValue && CurrentFrmValue <= ToValue) {
//alert('From, To page values should be unique for same doc');
IsFromValid = false;
}
// 9 5 9 10
if (CurrentToValue >= FromValue && CurrentToValue <= ToValue) {
//alert('From, To page values should be unique for same doc');
IsToValid = false;
}
if (CurrentFrmValue <= FromValue && CurrentToValue >= ToValue) {
//alert('From, To page values should be unique for same doc');
IsToValid = false;
}
if (IsFromValid && IsToValid)
{ }
else {
showToolTip(2, 'From, To page values should be unique for same batch');
IsValid = false;
//CurrentRefObj.value = "";
objTo.value = "";
objFrom.focus();
break;
}
}
}
// else if (i != 1) {
// showToolTip(2, 'Please select before input From, To page values');
// row.cells[4].childNodes[0].value = "";
// row.cells[5].childNodes[0].value = "";
// row.cells[1].childNodes[0].focus();
// break;
// }//SELECT
} //for
return IsValid;
}
}
}