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

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

1 Answer 77 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Kirk Thomas
Top achievements
Rank 1
Kirk Thomas asked on 23 Aug 2011, 05:00 PM
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";
        }
    }

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Sep 2011, 11:01 AM
Hello Krik,

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

Thanks,
Shinu.
Tags
Calendar
Asked by
Kirk Thomas
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or