
fred williams
Top achievements
Rank 1
fred williams
asked on 30 Jul 2010, 03:09 PM
I created a custom edit form, and I have a raddatepicker which I'd like to bind to a date type field in my database.
<telerik:RadDatePicker ID="dtStart" runat="server" Width="200px" SelectedDate='<%# Bind("StartDate") %>'/>
when I try to access th edit form I receive this "Specified cast is not valid" error. Some of the values int he database are Null. I don't know if that has anything to do with it. Please advise.
<telerik:RadDatePicker ID="dtStart" runat="server" Width="200px" SelectedDate='<%# Bind("StartDate") %>'/>
when I try to access th edit form I receive this "Specified cast is not valid" error. Some of the values int he database are Null. I don't know if that has anything to do with it. Please advise.
4 Answers, 1 is accepted
0
Accepted

Shinu
Top achievements
Rank 2
answered on 02 Aug 2010, 07:26 AM
Hello,
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, i.e. the input value will be empty.
ASPX:
<telerik:RadDatePicker ID="dtStart" runat="server" Width="200px" DbSelectedDate='<%# Bind("StartDate") %>'/>
Regards,
Shinu.
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, i.e. the input value will be empty.
ASPX:
<telerik:RadDatePicker ID="dtStart" runat="server" Width="200px" DbSelectedDate='<%# Bind("StartDate") %>'/>
Regards,
Shinu.
0

Jerry T.
Top achievements
Rank 1
answered on 25 Jan 2011, 05:24 PM
Shinu,
What happens when one tries that way and gets this error:
Value of '1/1/1900 12:00:00 AM' is not valid for 'SelectedDate'. 'SelectedDate' should be between 'MinDate' and 'MaxDate'.
Parameter name: SelectedDate
here is the line in markup:
<telerik:RadDatePicker ID="rdpEndDate" runat="server" ZIndex="10000" DateInput-DateFormat="MM/dd/yyyy" DateInput-DisplayDateFormat="MM/dd/yyyy" DbSelectedDate='<%# Eval("EndDate") %>' Enabled="false" />
I've tried it with this method, too:
SelectedDate='<%# If((Eval("EndDate") IsNot Nothing AndAlso TypeOf Eval("EndDate") Is DateTime), Convert.ToDateTime(Eval("EndDate")), CType(Nothing, System.Nullable(Of DateTime))) %>'
Same error as above.
Help?
Jerry
What happens when one tries that way and gets this error:
Value of '1/1/1900 12:00:00 AM' is not valid for 'SelectedDate'. 'SelectedDate' should be between 'MinDate' and 'MaxDate'.
Parameter name: SelectedDate
here is the line in markup:
<telerik:RadDatePicker ID="rdpEndDate" runat="server" ZIndex="10000" DateInput-DateFormat="MM/dd/yyyy" DateInput-DisplayDateFormat="MM/dd/yyyy" DbSelectedDate='<%# Eval("EndDate") %>' Enabled="false" />
I've tried it with this method, too:
SelectedDate='<%# If((Eval("EndDate") IsNot Nothing AndAlso TypeOf Eval("EndDate") Is DateTime), Convert.ToDateTime(Eval("EndDate")), CType(Nothing, System.Nullable(Of DateTime))) %>'
Same error as above.
Help?
Jerry
0
Hello Jerry,
If using DbSelectedDate the application should not throw an exception if the new value is null or DBNull. Setting a null value should internally revert the SelectedDate to the null value, i.e. the input value will be empty.
Therefore, we would need more details in order to locate the cause of the issue. Can you provide us with a set of steps to follow in order to create a project replicating the erroneous behavior?
Kind regards,
Tsvetina
the Telerik team
If using DbSelectedDate the application should not throw an exception if the new value is null or DBNull. Setting a null value should internally revert the SelectedDate to the null value, i.e. the input value will be empty.
Therefore, we would need more details in order to locate the cause of the issue. Can you provide us with a set of steps to follow in order to create a project replicating the erroneous behavior?
Kind regards,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0

Jerry T.
Top achievements
Rank 1
answered on 31 Jan 2011, 03:32 PM
Tsvetina,
I resolved the issue (as per this thread http://www.telerik.com/community/forums/aspnet/grid/null-raddatepicker-in-grid-error.aspx )
It was an empty string returning from a stored proc that should have been returning a Null value.
I resolved the issue (as per this thread http://www.telerik.com/community/forums/aspnet/grid/null-raddatepicker-in-grid-error.aspx )
It was an empty string returning from a stored proc that should have been returning a Null value.