简体   繁体   中英

Specified cast is not valid for the date picker

I try to check null before evaluate the date in my picker because i allow to enter no date :

 <telerik:RadDatePicker ID="rpick_to_date" runat="server" Visible="false" SelectedDate='<%# Eval("to_date") == null ? "" : Eval("to_date") %>'>
                                            <Calendar UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x">
                                            </Calendar>
                                            <DatePopupButton HoverImageUrl="" ImageUrl="" />
                                            <DateInput DateFormat="dd/MM/yyyy" DisplayDateFormat="dd/MM/yyyy">
                                            </DateInput>
 </telerik:RadDatePicker>

but i get the following error all the time :

Specified cast is not valid.

I believe you should be using DbSelectedDate property to bind the value instead of SelectedDate

Use the DbSelectedDate property than SelectedDate to get or set the date content of RadDatePicker in a database friendly way. The only difference with SelectedDate is that it will not throw an exception if the new value is null or DBNull. Setting a null value will internally revert the SelectedDate to the null value, ie the input value will be empty.

From here

您可以使用此代码(删除字符串“”) SelectedDateNullable<DateTime>

SelectedDate='<%# Eval("to_date")%>'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM