Search code examples
c#asp.netcalendarcalendar-control

asp.net calendar control. Date selectable after 2 days from the current


Is it possible to restrict which dates are selectable in the calendar control eg so that a date can only be selected once it's at least two days ago?


Solution

  • You can handle the calendar control's DayRender event to control which days are visible/selectable (as seen in this forum discussion):

    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        if (e.Day.Date >= DateTime.Now.Date && e.Day.Date <= DateTime.Now.AddDays(2))
            e.Cell.Visible = true;
        else
            e.Cell.Visible = false;
    }