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

Set SelectedDate RadDatePicker in Edit Form in RadGrid

1 Answer 284 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Yefta
Top achievements
Rank 1
Yefta asked on 09 Sep 2015, 10:56 AM

Hi, i have a RadDatePicker in EditForm in RadGrid.
The column in RadGrid consist of EditButtonColumn, Name, StartDate, EndDate.
when i click Edit, it shows error:

Sys.WebForms.PageRequestManagerServerErrorException: Specified cast is not valid.


I assume this is because the value StartDate and EndDate is empty/null.

my code to assign the value to RadDatePicker is like this:

<telerik:RadDatePicker ID="radStartDate" runat="server" Culture="en-US" TabIndex="8" Skin="MetroTouch" SelectedDate='<%# Bind("StartDate") %>'>
    <Calendar ID="Calendar1" runat="server">
        <SpecialDays>
            <telerik:RadCalendarDay Repeatable="Today" ItemStyle-BackColor="Yellow">
            </telerik:RadCalendarDay>
        </SpecialDays>
    </Calendar>
    <DateInput DisplayDateFormat="d/M/yyyy" DateFormat="d/M/yyyy" LabelWidth="40%" TabIndex="6">
    </DateInput>
</telerik:RadDatePicker>
 
<telerik:RadDatePicker ID="radEndDate" runat="server" Culture="en-US" TabIndex="9"  Skin="MetroTouch" SelectedDate='<%# Bind("EndDate") %>' >
    <Calendar ID="Calendar2" runat="server">
        <SpecialDays>
            <telerik:RadCalendarDay Repeatable="Today" ItemStyle-BackColor="Yellow">
            </telerik:RadCalendarDay>
        </SpecialDays>
    </Calendar>
    <DateInput DisplayDateFormat="d/M/yyyy" DateFormat="d/M/yyyy" LabelWidth="40%" TabIndex="6">
    </DateInput>
</telerik:RadDatePicker>


How to set RadDatePicker, when there's no value, shows no error. And if there's a value, the value of StartDate and EndDate will set to TextField and SelectedDate in RadDatePicker 

Thank you very much

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 11 Sep 2015, 01:24 PM
Hi Yefta,

Note that the SelectedDate property of RadDateTimePicker returns a nullable type. Thus, you should ensure that the corresponding fields accept nullable DateTime values. Moreover, you can check when saving the data if there are no dates entered. If this is the case you can pass a default value to the data source.

Also if the dates are required you can add validation to the grid columns. Thus, the user would not be able to submit the data before entering dates.

Regards,
Viktor Tachev
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
DatePicker
Asked by
Yefta
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or