
Pether Wiklander
Top achievements
Rank 2
Pether Wiklander
asked on 27 Oct 2008, 02:03 PM
Hi,
My data source returns DateTime.MinValue as null when no date is set by the user. This will be shown as 0001-01-01 00:00:00 in the RadGrid.
Question 1: Is it possible to change the behavior so that DateTime.MinValue will result in EmptyDataText showing?
Question 2: When changing into edit mode... How can I avoid getting exceptions when SelectedDate is DateTime.MinValue?
Best regards,
Pether Wiklander
My data source returns DateTime.MinValue as null when no date is set by the user. This will be shown as 0001-01-01 00:00:00 in the RadGrid.
Question 1: Is it possible to change the behavior so that DateTime.MinValue will result in EmptyDataText showing?
Question 2: When changing into edit mode... How can I avoid getting exceptions when SelectedDate is DateTime.MinValue?
Best regards,
Pether Wiklander
8 Answers, 1 is accepted
0
Accepted
Hello Pether,
Test whether the following approach is suitable for your scenario:
Q1:
Q2:
Kind regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Test whether the following approach is suitable for your scenario:
Q1:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem && DateTime.Parse(((GridDataItem)e.Item)["myDateColumn"].Text) == DateTime.MinValue) |
((GridDataItem)e.Item)["myDateColumn"].Text = "no date"; |
} |
Q2:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if (e.Item.IsInEditMode) |
((e.Item as GridEditFormItem)["myDateColumn"].Controls[0] as RadDatePicker).MinDate = DateTime.MinValue; |
} |
Kind regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Pether Wiklander
Top achievements
Rank 2
answered on 27 Oct 2008, 02:39 PM
Hi Daniel,
That works great! Thank you!
// Pether
That works great! Thank you!
// Pether
0

Pether Wiklander
Top achievements
Rank 2
answered on 27 Oct 2008, 04:42 PM
Is it possible to change the input field, when changing to edit mode, so that it is empty when SelectedDate is DateTime.MinValue?
0
Hello Pether,
Please try this code-snippet:
Kind regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Please try this code-snippet:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if (e.Item.IsInEditMode) |
{ |
RadDatePicker datePicker = (e.Item as GridEditFormItem)["myDateColumn"].Controls[0] as RadDatePicker; |
if (datePicker.SelectedDate == DateTime.MinValue) |
datePicker.DateInput.Text = ""; |
} |
} |
Kind regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Pether Wiklander
Top achievements
Rank 2
answered on 28 Oct 2008, 08:22 AM
Hi Daniel,
The textbox still shows 0001-01-01. When I debug, I can see that SelectedValue is still null when the item is created. I tried changing the condition to
The textbox still shows 0001-01-01. When I debug, I can see that SelectedValue is still null when the item is created. I tried changing the condition to
if( datePicker.SelectedDate == DateTime.MinValue || datePicker.SelectedDate == null )
datePicker.DateInput.Text = string.Empty;
...but no luck. Any suggestions?
// Pether
0
Accepted
Hello Pether,
I suggest you to include a little modification to the previous code:
Best regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I suggest you to include a little modification to the previous code:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item.IsInEditMode) |
{ |
RadDatePicker datePicker = (e.Item as GridEditFormItem)["myDateColumn"].Controls[0] as RadDatePicker; |
if (datePicker.SelectedDate == DateTime.MinValue) |
datePicker.Clear(); |
} |
} |
Best regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

JJ
Top achievements
Rank 1
answered on 16 Nov 2011, 07:48 PM
I am still not able to make the datetime be empty when in edit mode while it is MinDate.
On ItemCreated, I tried below, not work
Please help if you know.
Thanks
On ItemCreated, I tried below, not work
RadDatePicker datePicker = (e.Item as GridEditFormItem)["ExpirationDate"].Controls[0] as RadDatePicker;
((e.Item as GridEditFormItem)["ExpirationDate"].Controls[0] as RadDatePicker).MinDate = DateTime.MinValue;
if (datePicker.SelectedDate == DateTime.MinValue || datePicker.SelectedDate == null)
{
datePicker.DbSelectedDate = null;
datePicker.Clear();
}
Please help if you know.
Thanks
0

Shinu
Top achievements
Rank 2
answered on 17 Nov 2011, 05:48 AM
Hello,,
Try the following code snippet in ItemDataBound event which worked as expected.
C#:
-Shinu.
Try the following code snippet in ItemDataBound event which worked as expected.
C#:
protected
void
grid_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormItem && e.Item.IsInEditMode)
{
GridEditFormItemitm = (GridEditFormItem)e.Item;
RadDatePicker pkr = (RadDatePicker)itm[
"ExpirationDate"
].Controls[0];
if
(pkr.SelectedDate == DateTime.MinValue)
pkr.Clear();
}
}
-Shinu.