Max and Min date error in date picker

2 posts, 0 answers
  1. Guruvu
    Guruvu avatar
    32 posts
    Member since:
    Sep 2010

    Posted 12 Jul 2011 Link to this post

    Hi,

    In my applicationn i had a RadDatePicker with the following syntax:

    <telerik:RadDatePicker ID="txtDate" Runat="server" Skin="Sunset" 
                     FocusedDate="" MinDate="01/01/2006" ShowPopupOnFocus="True" TabIndex="20" 
                     Width="155px" MaxDate="01/01/2020">
                        <Calendar UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" 
                                             ViewSelectorText="x" Skin="Sunset"></Calendar>
                                           <DatePopupButton ImageUrl="" HoverImageUrl="" TabIndex="20"></DatePopupButton>
                        <DateInput DisplayDateFormat="dd/MM/yyyy" DateFormat="MM/dd/yyyy" TabIndex="20"></DateInput>
                 </telerik:RadDatePicker>

    My requirement is i need to bind 10 days back date from today's date to RadDatePicker with the following syntax:

    txtDate.SelectedDate =DateTime.Now.Date.AddDays(-10);

    Here i am getting the following error:

    Value of '7/2/2011 12:00:00 AM' is not valid for 'SelectedDate'. 'SelectedDate' should be between 'MinDate' and 'MaxDate'.
    Parameter name: SelectedDate

    Any one please suggest me the solution for this?

    It's very urgent...

    Thanks in advance...
  2. Vasil
    Admin
    Vasil avatar
    1638 posts

    Posted 15 Jul 2011 Link to this post

    Hi Guruvu,

    Try to use Subtract method of the DateTime object to go back with 10 days:

    DateTime dt = DateTime.Now;
    TimeSpan tenDays = new TimeSpan(10,0,0,0);
    dt = dt.Subtract(tenDays);
     
    RadDatePicker1.SelectedDate = dt;

    Greetings,
    Vasil
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top