This is a migrated thread and some comments may be shown as answers.

[Solved] Column data validations - Masked

2 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 14 Mar 2013, 06:48 PM
I have a field in my grid for an email address.  I would like to add a regular expression validator to ensure the format.  Currently I have a required field validator which works but is not sufficient.  I've searched but haven't found a working example.

I also have a date field and would like to set a valid range validator to it but I need to set the min/max values from my code behind file.  I have managed to set the min/max date of the editor using the ItemDataBound event as a work around but would like to know if this is possible.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 15 Mar 2013, 04:56 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)
 {
            GridEditableItem item = e.Item as GridEditableItem;            
              GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("EmailId);
              TableCell cell = (TableCell)editor.TextBoxControl.Parent;
              RegularExpressionValidator val = new RegularExpressionValidator();
              val.ControlToValidate = editor.TextBoxControl.ID;
              val.ValidationExpression=(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
              val.ErrorMessage = "input valid email address";
              cell.Controls.Add(val);
  }
}

Thanks,
Shinu
0
J
Top achievements
Rank 1
answered on 15 Mar 2013, 01:19 PM
Worked like a charm.  I still think it's silly that we can't add anything other than required field validators via mark up, but it's working and that's what I needed.

Thanks so much.
Tags
Grid
Asked by
J
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
J
Top achievements
Rank 1
Share this question
or