only allow second and fourth Tuesdays of a month to be selectable

2 posts, 0 answers
  1. Kirk Thomas
    Kirk Thomas avatar
    23 posts
    Member since:
    Aug 2009

    Posted 23 Aug 2011 Link to this post

    Hello,

    I would like to limit the selectable dates in a calendar to only be the 2nd and 4th tuesdays of each month.  I was able to set this in the server side ondayrender event by using the code below, however I am still able to select days that I added to the special days collection.  The other issue is recreating this functionality in the client side ondayrender event.  If there is a better way to go about doing this I am all ears.

    Thanks,

    Kirk

    protected void Calendar_OnDayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
        {
            DateTime dt = new DateTime();
            dt = e.Day.Date;
            string month = RadCalendar1.CalendarView.TitleContent;
            month = month.Substring(0, month.Length - 5);
            System.Globalization.DateTimeFormatInfo info = new System.Globalization.DateTimeFormatInfo();
            string[] monthNames;
     
            monthNames = info.MonthNames;
     
            if (dt.DayOfWeek == DayOfWeek.Monday && monthNames[dt.Month - 1] == month)
            {
                 
                dayCount = dayCount + 1;
     
                if (dayCount != 2 && dayCount != 4)
                {
                    RadCalendarDay calendarDay = new RadCalendarDay();
                    calendarDay.Date = e.Day.Date;
                    calendarDay.IsSelectable = false;
                    calendarDay.IsDisabled = true;
                    RadDatePicker1.Calendar.SpecialDays.Add(calendarDay);
                    e.Cell.BackColor = System.Drawing.Color.Gray;
                    e.Cell.Text = "<span>" + e.Day.Date.Day + "</span>";
                    e.Cell.ID = "";
                    e.Cell.ControlStyle.CssClass = "disabledDay";
                }
            }
            else
            {
                RadCalendarDay calendarDay = new RadCalendarDay();
                calendarDay.Date = e.Day.Date;
                calendarDay.IsSelectable = false;
                calendarDay.IsDisabled = true;
                RadDatePicker1.Calendar.SpecialDays.Add(calendarDay);
                e.Cell.BackColor = System.Drawing.Color.Gray;
                e.Cell.Text = "<span>" + e.Day.Date.Day + "</span>";
                e.Cell.ID = "";
                e.Cell.ControlStyle.CssClass = "disabledDay";
            }
        }
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Sep 2011 Link to this post

    Hello Krik,

    You can try the approach in the following code library.
    Disabling calendar days.

    Thanks,
    Shinu.
Back to Top