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

Compare datetime

3 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yadi
Top achievements
Rank 1
Yadi asked on 26 Dec 2012, 01:05 PM
how to campare datetime in radgrid itemdatabound ?

3 Answers, 1 is accepted

Sort by
0
Accepted
Elliott
Top achievements
Rank 2
answered on 28 Dec 2012, 08:37 PM
be more specific
also, some code might be nice

I think if you have a GridDateTimeColumn then the filter is a RadCalendar
what is it you want to do for a date - i.e. dates of a certain range change the back color on the row

"GridDateTimeColumn - with option to choose RadDatePicker, RadDateTimePicker, RadTimePicker or simply RadDateInput as editor. To choose the editor type use the PickerType property of the column"
0
Accepted
Shinu
Top achievements
Rank 2
answered on 02 Jan 2013, 06:22 AM
Hi,

Try the following code to compare dates.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
     GridDataItem item = (GridDataItem)e.Item;
     RadDatePicker picker1 = (RadDatePicker)item.FindControl("RadDatePicker1");
     RadDatePicker picker2 = (RadDatePicker)item.FindControl("RadDatePicker2");
     CompareValidator compValidate = (CompareValidator)item.FindControl("CompareValidator1");
     compValidate.ControlToValidate =picker1.ID;
     compValidate.ControlToCompare = picker2.ID;
     compValidate.ValueToCompare = DateTime.Now.ToShortDateString();
     compValidate.Type = ValidationDataType.Date;
     compValidate.Operator = ValidationCompareOperator.LessThanEqual;
     compValidate.ErrorMessage = "EndDate should not be less than StartDate"
  }
}

Thanks,
Shinu.
0
Yadi
Top achievements
Rank 1
answered on 21 Jan 2013, 03:57 AM
thanks

it work for me
Tags
Grid
Asked by
Yadi
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Yadi
Top achievements
Rank 1
Share this question
or