Thursday, 18 October 2012

Gridview Javascript Validation : function ValidateData() { var grid = document.getElementById("<%= grdBookinStock.ClientID %>"); var cellProductCode; var cellOwner; var cellWarehouse; var cellBin; var cellQuantity; var cellProductCodeValue; var cellOwnerValue; var cellWarehouseValue; var cellBinValue; var cellQuantityValue; if (grid.rows.length > 0) {//loop starts from 1. rows[0] points to the header. for (i = 1; i < grid.rows.length; i++) { cellProductCode = grid.rows[i].cells[0]; cellOwner = grid.rows[i].cells[1]; cellWarehouse = grid.rows[i].cells[2]; cellBin = grid.rows[i].cells[3]; cellQuantity = grid.rows[i].cells[4]; for (j = 0; j < cellProductCode.childNodes.length; j++) { //if childNode type is CheckBox if (cellProductCode.childNodes[j].type == "text") { cellProductCodeValue = cellProductCode.childNodes[j].value; //alert(cellProductCodeValue); } } for (j = 0; j < cellOwner.childNodes.length; j++) { //if childNode type is CheckBox if (cellOwner.childNodes[j].tagName == "SELECT") { cellOwnerValue = cellOwner.childNodes[j].value; // alert(cellOwnerValue); } } for (j = 0; j < cellWarehouse.childNodes.length; j++) { if (cellWarehouse.childNodes[j].tagName == "SELECT") { cellWarehouseValue = cellWarehouse.childNodes[j].value; //alert(cellWarehouseValue); } } for (j = 0; j < cellBin.childNodes.length; j++) { if (cellBin.childNodes[j].type == "text") { cellBinValue = cellBin.childNodes[j].value; //alert(cellBinValue); } } for (j = 0; j < cellQuantity.childNodes.length; j++) { if (cellQuantity.childNodes[j].type == "text") { cellQuantityValue = cellQuantity.childNodes[j].value; // alert(cellQuantityValue); } } if (cellProductCodeValue != "" || cellOwnerValue != "0" || cellWarehouseValue != "" || cellBinValue != "" || cellQuantityValue != "") { if (cellProductCodeValue == "") { alert('Enter product code'); return false; } if (cellOwnerValue == "0") { alert('Select owner.'); return false; } if (cellWarehouseValue == "0") { alert('Select warehouse.'); return false; } if (cellBinValue == "") { alert('Enter bin.'); return false; } if (cellQuantityValue == "") { alert('Enter quantity.'); return false; } } function SetWarehouseIdtoHdnField() { var hdn =document.getElementById('ctl00_ContentPlaceHolder1_hdnWarehouseId') AjaxFunctions.SetValueWarehouse(hdn.value); } } }//return true;if (confirm("Are you sure, you want to save the data?")) {return true; }else {return false; } }

No comments:

Post a Comment