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

RadTimePicker SelectedTime.Value Nullable Object must have Value

1 Answer 270 Views
TimePicker
This is a migrated thread and some comments may be shown as answers.
Jackie
Top achievements
Rank 1
Jackie asked on 19 Sep 2017, 09:21 PM
I'm reading in values from several TimePickers that may or may not be null. SelectedTime.Value throws the mentioned error when the value is a null and using DbSelectedDate with a (TimeSpan?) cast is invalid. Currently I'm accepting it as a (DateTime?) instead and breaking it down in an extra step. Is there a more elegant solution or is this the standard practice?

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 22 Sep 2017, 07:26 AM
Hello Jackie,

Yes, you are correct. The pickers return nullable objects because the user could also have removed any date or time from the input. You can use some if statements whether this is the case using the RadTimePicker1.SelectedDate.HasValue boolean. Of course, there are also other ways to achieve that:
protected void Page_Load(object sender, EventArgs e)
{
    DateTime? date = RadDateTimePicker1.SelectedDate;
    DateTime? date2 = RadTimePicker1.SelectedDate;
    TimeSpan? time = RadTimePicker1.SelectedTime;
 
    TimeSpan nonNullableValue = RadTimePicker1.SelectedTime ?? new TimeSpan(0);
}

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TimePicker
Asked by
Jackie
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or