3 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 07 Oct 2010, 05:40 AM
Hello Kathy,
The documentation shows how to add the validation controls in editform of RadGrid. I hope this helps.
Validation
-Shinu.
The documentation shows how to add the validation controls in editform of RadGrid. I hope this helps.
Validation
-Shinu.
0

Kathy
Top achievements
Rank 1
answered on 08 Oct 2010, 09:05 PM
I got the validators to work for the numeric columns. But I'm having difficulty with the DateTimeColumn when using a DatePicker. I have 2 date columns, start date and end date and all I need to do is make sure the end date is after the start date. Here's what I have:
But now, it says that it can't find the controls enddateID and startedateID.
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
GridDateTimeColumnEditor editor = (GridDateTimeColumnEditor)editedItem.EditManager.GetColumnEditor("StartDate");
RadDateInput cell = (RadDateInput)editor.PickerControl.DateInput;
cell.ID = "startdateID";
GridDateTimeColumnEditor editorend = (GridDateTimeColumnEditor)editedItem.EditManager.GetColumnEditor("EndDate");
RadDateInput cellend = (RadDateInput)editorend.PickerControl.DateInput;
cellend.ID = "enddateID";
CompareValidator compValidate = new CompareValidator();
compValidate.ControlToValidate = cell.ID;
compValidate.ControlToCompare = cellend.ID;
compValidate.Operator = ValidationCompareOperator.GreaterThan;
compValidate.ErrorMessage = "EndDate should not be less than StartDate";
cell.Controls.Add(compValidate);
cellend.Controls.Add(compValidate);
0
Hello Kathy,
This code should work for you:
Information about how to add validators to RadGrid columns can be found in this help article and in the live demo here.
Sincerely yours,
Vasil
the Telerik team
This code should work for you:
protected
void
RadGrid1_ItemCreated(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = e.Item
as
GridEditableItem;
GridDateTimeColumnEditor editorStartDate = (GridDateTimeColumnEditor)item.EditManager.GetColumnEditor(
"StartDate"
);
GridDateTimeColumnEditor editorEndDate = (GridDateTimeColumnEditor)item.EditManager.GetColumnEditor(
"EndDate"
);
TableCell cellStart = (TableCell)editorStartDate.PickerControl.Parent;
CompareValidator compareValidator =
new
CompareValidator();
compareValidator.ID =
"compareValidator"
;
compareValidator.ControlToValidate = editorStartDate.PickerControl.ID;
compareValidator.ControlToCompare = editorEndDate.PickerControl.ID;
compareValidator.Operator = ValidationCompareOperator.LessThan;
compareValidator.Type = ValidationDataType.Date;
compareValidator.ErrorMessage =
"Start date must be before the end date!"
;
cellStart.Controls.Add(compareValidator);
}
}
Information about how to add validators to RadGrid columns can be found in this help article and in the live demo here.
Sincerely yours,
Vasil
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items