asp.net calendar control. Date selectable after 2

2019-08-07 01:09发布

问题:

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?

回答1:

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;
}


回答2:

Put this in your page load:

Calendar1.SelectedDate = DateTime.Now.AddDays(2);