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

compare validator in code behind

1 Answer 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erin
Top achievements
Rank 1
Erin asked on 28 Nov 2013, 10:37 AM
Hi,
How to create a compare validator in code behind if i want to compare the values of two column which are griddatetimecolumns.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Nov 2013, 10:52 AM
Hi Erin,

Please try the following code snippet to compare two date fields in edit/insert mode.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
  if (e.Item is GridEditableItem && e.Item.IsInEditMode)
  {
    GridEditableItem item = e.Item as GridEditableItem;              
    RadDatePicker start = (RadDatePicker)item["StartDate"].Controls[0];
    RadDatePicker end = (RadDatePicker)item["EndDate"].Controls[0];
    TableCell cell = (TableCell)start.Parent;
    CompareValidator val = new CompareValidator();
    val.ControlToCompare = start.ID;
    val.ControlToValidate = end.ID;
    val.Operator = ValidationCompareOperator.Equal; // Give your required Operator
    val.ErrorMessage = "Error message";
    val.ForeColor = Color.Red;
    cell.Controls.Add(val);
  }           
}

Thanks,
Shinu
Tags
Grid
Asked by
Erin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or