This is a migrated thread and some comments may be shown as answers.

Max and Min date error in date picker

1 Answer 660 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Guruvu
Top achievements
Rank 1
Guruvu asked on 12 Jul 2011, 11:40 AM
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...

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 15 Jul 2011, 09:36 AM
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!

Tags
Calendar
Asked by
Guruvu
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or