Databind RadTimePicker to SQL Time Column

5 posts, 0 answers
  1. Travis
    Travis avatar
    9 posts
    Member since:
    Nov 2007

    Posted 29 Jan 2010 Link to this post

    I have a RadTimePicker in a RadGrid.  The grid is bound to a SqlDataSource which is connected to a SQL Server 2008 database table.  The table contains a column with a datatype of "time," which is not null.

    When I attempt to bind a RadTimePicker to this time column, I receive the error 
    System.InvalidCastException:Specified cast is not valid.

    This is how I'm attempting to do the databinding:
    <telerik:RadTimePicker ID="RadTimePicker1" runat="server" DbSelectedDate='<%# Bind("TimeMon") %>' /> 


    Please advise if I am missing something, or if the time data type in SQL Server is too new, preventing me from doing this.  I am using RadControls for ASP.NET AJAX 2008.3 1314

    Thanks!
    Travis
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 04 Feb 2010 Link to this post

    Hello Travis,

    The code supplied looks correct, and should handle the task at hand. However, in order to further track the problem, it will be best if you open a formal support ticket and send us a small working project, demonstrating the setup, and the error you received. Upon reviewing it, we will advise you further.

    Additionally, I suggest you review the following articles which elaborates on this subject:
    Data Binding
    Using RadDatePicker/RadDateTimePicker as editor in template column od RadGrid

    Kind regards,
    Pavlina
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sean P. Jaeger
    Sean P. Jaeger avatar
    1 posts
    Member since:
    Jan 2007

    Posted 04 Feb 2010 Link to this post

    I am having the exact same issue with setting the value of DbSelectedDate from the code behind:

     

    radtmpkBackupTimeAddUpdate.DbSelectedDate = schedule.BackupTime; 

    Where "BackupTime" is a SQL 2008 Time data type.

    The error received is:

    Specified cast is not valid.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: Specified cast is not valid.

    Source Error:

    Line 64: 
    Line 65:         radcmbClientAddUpdate.Items.FindItemByValue(keys["BackupClientID"].ToString()).Selected = true;
    Line 66: radtmpkBackupTimeAddUpdate.DbSelectedDate = schedule.BackupTime;Line 67: 
    Line 68:     }

    Source File: c:\inetpub\wwwroot\Amex.Sdn.Aeln.BackupUtility\Default.aspx.cs    Line: 66
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 05 Feb 2010 Link to this post

    Hi Sean,

    Based on the information supplied I suspect that you are trying to bind non-DateTime value to RadTimePicker . However, in order to be sure, it would be best if you open a formal support ticket, and send us the problematic implementation, for  further review. We will test it locally, and get back to you with our findings.

    Kind regards,
    Pavlina
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  6. Oscar
    Oscar avatar
    4 posts
    Member since:
    Jul 2011

    Posted 16 May 2012 Link to this post

    I had the same problem when editing the RadGrid with RadTimePicker with column of type time(7) in SQL Server 2008. I solved it by changing my sql query to convert the type of time 15:00:00 to 3:00PM:
     
     SELECT ID,SUBSTRING(CAST(CAST(MyHour AS DATETIME) AS VARCHAR),13,7) AS MyHour FROM MyTable
     
     I hope this post can help you.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017