Hi,
I want to validate data grd contents , some of the validations which I want to do is
1. When save button is clicked the system should not allow blank fields
2. Combo boxes in data grid
3. DTP pickers
please send me some code for these validations
Thnaks in Advance,
A.Durga Prasad
Data Grid Validation
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Niradhip ChakrabortyRank #428 · 5.8K pointsPosted May 16, 2008, 10:26 AM EDT
You can do it using javascript. call this java script function on click of save button.
say dgrdDayEnd is name of my datagrid. strEmail,strTxtCtrlName name of my textbox.
I have done it for textbox do it for other control in same way.
function btnClick(){
var obj = window.document.getElementById("dgrdDayEnd")
var intLoop;
var intRowCnt;
if(window.document.getElementsByName("dgrdDayEnd").length !=0) {
intRowCnt = obj.rows.length ;
for(intLoop=1;intLoop<=intRowCnt;intLoop++){
if (intLoop < 9){
var strTxtCtrlName = 'dgrdDayEnd_ctl0' + (intLoop+1) + '_txtDayEnd';
var strCtrlName = 'dgrdDayEnd_ctl0' + (intLoop+1) + '_chkDayEnd';
var strEmail = 'dgrdDayEnd_ctl0' + (intLoop+1) + '_txtEmail';
}
else{
var strTxtCtrlName = 'dgrdDayEnd_ctl' + (intLoop+1) + '_txtDayEnd';
var strCtrlName = 'dgrdDayEnd_ctl' + (intLoop+1) + '_chkDayEnd';
var strEmail = 'dgrdDayEnd_ctl' + (intLoop+1) + '_txtEmail';
}
if (Trim(document.getElementById(strEmail).value) != '' && !isEmail(Trim(document.getElementById(strEmail).value))){
alert("Enter Valid Email Address ");
document.getElementById(strEmail).focus();
document.getElementById(strEmail).select();
return false;
}
if(window.document.getElementById(strTxtCtrlName).disabled == false){
if(window.document.getElementById(strTxtCtrlName).value == "" ||window.document.getElementById(strTxtCtrlName).value == 0){
alert("Please enter the No of Copies for DayEnd/No of Copies");
document.getElementById(strTxtCtrlName).focus();
document.getElementById(strTxtCtrlName).select();
return false;
}
}
}
}
durga prasad29 pointsPosted May 16, 2008, 9:58 PM EDT
I should not be using java script in my project, is there any other way to overcome this
problem.
Thanks in Advance,
A.Durga Prasad