Set SelectedDate RadDatePicker in Edit Form in RadGrid

2 posts, 0 answers
  1. Yefta
    Yefta avatar
    14 posts
    Member since:
    Mar 2015

    Posted 09 Sep 2015 Link to this post

    Hi, i have a RadDatePicker in EditForm in RadGrid.
    The column in RadGrid consist of EditButtonColumn, Name, StartDate, EndDate.
    when i click Edit, it shows error:

    Sys.WebForms.PageRequestManagerServerErrorException: Specified cast is not valid.


    I assume this is because the value StartDate and EndDate is empty/null.

    my code to assign the value to RadDatePicker is like this:

    <telerik:RadDatePicker ID="radStartDate" runat="server" Culture="en-US" TabIndex="8" Skin="MetroTouch" SelectedDate='<%# Bind("StartDate") %>'>
        <Calendar ID="Calendar1" runat="server">
            <SpecialDays>
                <telerik:RadCalendarDay Repeatable="Today" ItemStyle-BackColor="Yellow">
                </telerik:RadCalendarDay>
            </SpecialDays>
        </Calendar>
        <DateInput DisplayDateFormat="d/M/yyyy" DateFormat="d/M/yyyy" LabelWidth="40%" TabIndex="6">
        </DateInput>
    </telerik:RadDatePicker>
     
    <telerik:RadDatePicker ID="radEndDate" runat="server" Culture="en-US" TabIndex="9"  Skin="MetroTouch" SelectedDate='<%# Bind("EndDate") %>' >
        <Calendar ID="Calendar2" runat="server">
            <SpecialDays>
                <telerik:RadCalendarDay Repeatable="Today" ItemStyle-BackColor="Yellow">
                </telerik:RadCalendarDay>
            </SpecialDays>
        </Calendar>
        <DateInput DisplayDateFormat="d/M/yyyy" DateFormat="d/M/yyyy" LabelWidth="40%" TabIndex="6">
        </DateInput>
    </telerik:RadDatePicker>


    How to set RadDatePicker, when there's no value, shows no error. And if there's a value, the value of StartDate and EndDate will set to TextField and SelectedDate in RadDatePicker 

    Thank you very much
  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 11 Sep 2015 Link to this post

    Hi Yefta,

    Note that the SelectedDate property of RadDateTimePicker returns a nullable type. Thus, you should ensure that the corresponding fields accept nullable DateTime values. Moreover, you can check when saving the data if there are no dates entered. If this is the case you can pass a default value to the data source.

    Also if the dates are required you can add validation to the grid columns. Thus, the user would not be able to submit the data before entering dates.

    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top