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

十年热恋 提交于 2019-12-11 05:32:35

问题


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


来源:https://stackoverflow.com/questions/9500882/asp-net-calendar-control-date-selectable-after-2-days-from-the-current

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!