RadDatepicker Disabling dates and changing disabled dates on postback

3 posts, 0 answers
  1. Katie
    Katie avatar
    6 posts
    Member since:
    Jun 2012

    Posted 03 Jul 2012 Link to this post

    I need to be able to have a calendar which only allows the user to select a saturday if a 7 nights is chosen from a combo box on a form and to allow the user to just select a monday if an 4 nights is chosen from the combo box.

    I am currently using the RadDatepicker and have set it up to add the disabled dates for the year to the special days. So if a 7 is selected the dt variable will be every day except a saturday.
    RadCalendarDay holiday = new RadCalendarDay();
            holiday.Date = dt;
            holiday.IsSelectable = false;
            holiday.IsDisabled = true;
            CalendarPopup1.Calendar.SpecialDays.Add(holiday);

    I don't seem to be able to get this to work. I am also trying to reset the calendar whenever the combo box value changes. But can't get this to work either.
    public void ResetCalendar()
    {
        CalendarPopup1.Clear();
        CalendarPopup1.Calendar.SpecialDays.Clear();
    }

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Jul 2012 Link to this post

    Hi Katie,

    Here is the sample code that I tried based on your scenario.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
      <Items>
         <telerik:RadComboBoxItem Text="1" />
         <telerik:RadComboBoxItem Text="2" />
         <telerik:RadComboBoxItem Text="3" />
         <telerik:RadComboBoxItem Text="4" />
         <telerik:RadComboBoxItem Text="5" />
         <telerik:RadComboBoxItem Text="6" />
         <telerik:RadComboBoxItem Text="7" />
      </Items>
    </telerik:RadComboBox>
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server">
    </telerik:RadDatePicker>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" />

    C#:
    protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (RadComboBox1.SelectedItem.Text == "7")
            {
                RadDatePicker1.Calendar.DayRender += new Telerik.Web.UI.Calendar.DayRenderEventHandler(Calendar_DayRender);
            }
            else if(RadComboBox1.SelectedItem.Text=="4")
            {
                RadDatePicker1.Calendar.DayRender += new Telerik.Web.UI.Calendar.DayRenderEventHandler(Calendar_DayRender);
            }
        }
    void  Calendar_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
        {
            if (RadComboBox1.SelectedItem.Text == "7")
            {
                if (e.Day.Date.DayOfWeek == DayOfWeek.Saturday)
                {
                     RadCalendarDay holiday = new RadCalendarDay();
                    holiday.Date = e.Day.Date;
                    holiday.IsSelectable = false;
                    holiday.IsDisabled = true;
                    RadDatePicker1.Calendar.SpecialDays.Add(holiday);
                }
            }
            else if (RadComboBox1.SelectedItem.Text == "4")
            {
                if (e.Day.Date.DayOfWeek == DayOfWeek.Monday)
                {
                    RadCalendarDay holiday = new RadCalendarDay();
                    holiday.Date = e.Day.Date;
                    holiday.IsSelectable = false;
                    holiday.IsDisabled = true;
                    RadDatePicker1.Calendar.SpecialDays.Add(holiday);
                }
            }
        }
    protected void Button1_Click(object sender, EventArgs e)
        {
            RadDatePicker1.Clear();
            RadDatePicker1.Calendar.SpecialDays.Clear();
        }

    Hope this helps.

    Thanks.
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Katie
    Katie avatar
    6 posts
    Member since:
    Jun 2012

    Posted 05 Jul 2012 Link to this post

    Thank you, that really helped, I have now got it working.
Back to Top