I am trying to validate the textbox populated in the datagrid, when an update button is clicked. I am using a bound column and using a regular expression to validate the text entered by the user. I am trying to do it dynamically. Below is the code I have and for some reason it is not validating..
TextBox txtOPLTarget = (TextBox) e.Item.Cells.Controls;
RegularExpressionValidator rexpValidator = new RegularExpressionValidator();
rexpValidator.Text = "Please enter a positive value";
rexpValidator.ControlToValidate = txtOPLTarget.ToString();
rexpValidator.Display = ValidatorDisplay.Dynamic;
rexpValidator.ID = "validate" + txtOPLTarget.ID;
//Adding the control to the datagrid...
Can anybody please let me know why it is not working?? Is there a better way to implement it??