I have a datagrid that has an edit function on it... since a lot of the data is phone numbers zip codes, emails, etc., I wanted to add validators to ensure data integrity. Problem is, I keep getting "Control to Validate cannot be blank" problems... look at what I've done:
RequiredFieldValidator rqr = new RequiredFieldValidator();
//add phone validator
RegularExpressionValidator rev = new RegularExpressionValidator();
rev.ErrorMessage = "*";
rev.ValidationExpression = @dotnet.itags.org."((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}";
rev.ControlToValidate = dgi.Cells[4].Controls[0].ID;
dgi.Cells[4].Controls.Add(rev);
rqr.ControlToValidate = dgi.Cells[4].Controls[0].ID;
dgi.Cells[4].Controls.Add(rqr);
If you have any ideas or resources, please let me know.You may want to try Controls[1] instead of 0. I have found that if the column is a template column and you place a control in the ItemTemplate section, the control index is 1.
No comments:
Post a Comment