asp.net日历控件。从当前2天后可选择日期

时间:2012-02-29 14:27:55

标签: c# asp.net calendar calendar-control

是否可以限制日历控件中可选择的日期,例如,只有在至少两天前才能选择日期?

2 个答案:

答案 0 :(得分:3)

您可以处理日历控件DayRender event以控制哪些日期可见/可选(如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;
}

答案 1 :(得分:1)

将其放入页面加载中:

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