Specified cast is not valid error with raddatepicker

5 posts, 1 answers
  1. fred williams
    fred williams avatar
    55 posts
    Member since:
    Feb 2010

    Posted 30 Jul 2010 Link to this post

    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.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Aug 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 25 Jan 2011 Link to this post

    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
  5. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 31 Jan 2011 Link to this post

    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
    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.
  6. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 31 Jan 2011 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017