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

Default to Today when null

2 Answers 40 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Rayne
Top achievements
Rank 1
Rayne asked on 10 Aug 2011, 08:16 PM
My date picker is bound to a DateTime field, but on the UI, the control allows the user to "delete" the value. This causes the validation to throw an error "Value '' cannot be converted". Is there any way to set the control to the current datetime when the user "deletes" the date in the box?

I'm also having this trouble with a bound combobox that doesn't allow null values. I want the user to be able to type in to select a value, but that means they can also remove the value (which causes the same error).

2 Answers, 1 is accepted

Sort by
0
Rayne
Top achievements
Rank 1
answered on 10 Aug 2011, 08:54 PM
I managed to work around it by handling the SelectionChanged event and checking for a SelectedValue. If null, then I set to DateTime.Now.
I also did the same thing with the combobox. if selected item is null, I set selectedvalue to 0 to trigger the data validation.

Is this the best way to handle this?
0
Boyan
Telerik team
answered on 11 Aug 2011, 04:14 PM
Hi Rayne,

For RadDatePicker you can also use the ParseDateTimeValue event and to implement your custom logic there. As for the RadComboBox I can't think of another way this can be done.

Best wishes,
Boyan
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
DatePicker
Asked by
Rayne
Top achievements
Rank 1
Answers by
Rayne
Top achievements
Rank 1
Boyan
Telerik team
Share this question
or