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

Cast exception when trying to populate DatePicker when adding new record

3 Answers 81 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 05 Aug 2010, 05:00 PM

Hi all,

I am using the below code to populate a DateInput when the user edits a record in a RadGrid so the Edit form is pre-populated with correct data. All is well until I try to Add a new record, because the ExpireDate variable is now NULL.

The Exception is:

An exception of type 'System.InvalidCastException' occurred in App_Web_xngshb9r.dll but was not handled in user code

Additional information: Specified cast is not valid.

And the code block (client-side):

<

 

telerik:RadDatePicker ID="RDP" runat="server" MinDate="01/01/1900" MaxDate="12/31/2100"

 

 

    SelectedDate='<%# Eval("ExpireDate") %>' TabIndex="2" OnSelectedDateChanged="RDP_SelectedDateChanged">

 

 

</telerik:RadDatePicker>

Any help would be greatly appreciated!

 

3 Answers, 1 is accepted

Sort by
0
Brad
Top achievements
Rank 1
answered on 05 Aug 2010, 08:47 PM
Figured it out. Just populated the DateInputs in Page_PreRender.
0
Accepted
Cori
Top achievements
Rank 2
answered on 06 Aug 2010, 04:34 PM
Hello Brad,

Instead of using: SelectedDate='<%# Eval("ExpireDate") %>' you should use DbSelectedDate='<%# Eval("ExpireDate") %>'. This way it can handle the null value. There's no need to populate it in the PreRender event.

I hope that helps.
0
Brad
Top achievements
Rank 1
answered on 06 Aug 2010, 08:14 PM
Worked like a charm :)

Thanks!
Tags
Calendar
Asked by
Brad
Top achievements
Rank 1
Answers by
Brad
Top achievements
Rank 1
Cori
Top achievements
Rank 2
Share this question
or