RadCalendar set date range based on start date selected

4 posts, 0 answers
  1. pmourfield
    pmourfield avatar
    32 posts
    Member since:
    Aug 2011

    Posted 02 Sep 2011 Link to this post

    Good morning everyone! Here is what I am trying to accomplish. I have two datepickers within a radgrid,  one is a start date and the other an end date. What I need is when the user clicks a date within start date is for the end date to automatically be populated with the date five days later. For example, if the user clicks the start date 9/1/2011, then the end date should automatically be set to 9/4/2011. Is there a setting within the raddatepicker or radcalendar that will do this or will I need to use javascript? Thank you in advance for your help!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Sep 2011 Link to this post

    Hello Joshua,

    Try the following scenario to set date range based on first RadDatePicker selected.
    aspx:
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server">
                <ClientEvents OnDateSelected="OnDateSelected" />
    </telerik:RadDatePicker>
    <telerik:RadDatePicker ID="RadDatePicker2" runat="server">
    </telerik:RadDatePicker>
    JS:
    <script type="text/javascript">
    function OnDateSelected(sender, args)
     {
       var dt = sender.get_selectedDate();
       var myDate = new Date(sender.get_selectedDate().format("MM/dd/yyyy"));
       myDate.setDate(myDate.getDate() + 4);
       var datepicker = $find("<%= RadDatePicker2.ClientID %>");
       datepicker.set_selectedDate(myDate);
     }
    </script>

    Thanks,
    Shinu.
  3. pmourfield
    pmourfield avatar
    32 posts
    Member since:
    Aug 2011

    Posted 02 Sep 2011 Link to this post

    Shinu,

    Thank you very much for your reply. While I believe this code will work, my datepickers are inside a radgrid edititemtemplate and the code is failing. I have tried a few different methods of finding the control but to no avail. Any ideas? Thank you again!
  4. pmourfield
    pmourfield avatar
    32 posts
    Member since:
    Aug 2011

    Posted 02 Sep 2011 Link to this post

    I was able to figure out a code-behind solution to this problem. In the properties of the begin date raddatepicker I set AutoPostBack = true. My codebehind is thus:

    protected void beginDatePicker_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
        {      
            RadDatePicker beginDatePicker = (RadDatePicker)sender;
     
            GridEditFormItem editItem = (GridEditFormItem)beginDatePicker.NamingContainer;
                     
            RadDatePicker endDatePicker = (RadDatePicker)editItem.FindControl("endDatePicker");
            endDatePicker.DbSelectedDate = (e.NewDate.Value.AddDays(4));
        }
Back to Top