Invalid Cast Problem

3 posts, 0 answers
  1. Steve
    Steve avatar
    1886 posts
    Member since:
    Dec 2008

    Posted 26 Feb 2013 Link to this post

    I have 2 RadDateTime controls inside my <FormTemplate>

    Editing works perfectly fine, but when I try and create a new throws this...?

    Any idea?...if I remove the SelectedDate property everything is fine again...

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

    Source Error:

    Line 243:                                <div class="inputItem">
    Line 244:                                    <label class="rcbLabel itemLabel">Opens:</label>
    Line 245:                                    <telerik:RadDateTimePicker ID="fromDatePicker" runat="server" Width="245px" DateInput-DateFormat="dddd MMM dd, yyyy h:mmtt" Skin="Sitefinity" SelectedDate='<%# Eval("FromDate") %>'>
    Line 246:                                        <DateInput runat="server" EnableSingleInputRendering="true" />
    Line 247:                                    </telerik:RadDateTimePicker>

    Source File: DesignBuilder\Default.aspx    Line: 245

    Stack Trace:

    [InvalidCastException: Specified cast is not valid.]
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Feb 2013 Link to this post


    I am not quite sure about your issue. One suggestion is that you can bind the date in edit mode as shown below.
    protected void RadTreeList1_ItemDataBound(object sender, Telerik.Web.UI.TreeListItemDataBoundEventArgs e)
        if (e.Item is TreeListEditFormItem && (e.Item as TreeListEditableItem).IsInEditMode)
            TreeListEditFormItem item = (TreeListEditFormItem)e.Item;
            RadDateTimePicker pkr = (RadDateTimePicker)item.FindControl("fromDatePicker");
            pkr.SelectedDate = Convert.ToDateTime(DataBinder.Eval(e.Item, "Fromdate").ToString());

  3. Steve
    Steve avatar
    1886 posts
    Member since:
    Dec 2008

    Posted 27 Feb 2013 Link to this post

    Thanks, turns out the answer was the oft-forgotten DbSelectedDate, not SelectedDate :)

    WHOOPS, thanks :)
Back to Top