【原创】.Net WebForm Calendar 日历控件常用方法

微软官方地址 https://msdn.microsoft.com/en-us/library/add3s294.aspx

1.设置日历控件单个日期Table Cell样式 颜色/外观/边距

protected void Calendar1_DayRender(object sender,
DayRenderEventArgs e)
{
// Display vacation dates in yellow boxes with purple borders.
Style vacationStyle = new Style();
vacationStyle.BackColor = System.Drawing.Color.Yellow;
vacationStyle.BorderColor = System.Drawing.Color.Purple;
vacationStyle.BorderWidth = 3; // Display weekend dates in green boxes.
Style weekendStyle = new Style();
weekendStyle.BackColor = System.Drawing.Color.Green; if ((e.Day.Date >= new DateTime(2000,11,23)) &&
(e.Day.Date <= new DateTime(2000,11,30)))
{
// Apply the vacation style to the vacation dates.
e.Cell.ApplyStyle(vacationStyle);
}
else if (e.Day.IsWeekend)
{
// Apply the weekend style to the weekend dates.
e.Cell.ApplyStyle(weekendStyle);
}
}

2.设置特定日期不可见/不可选的方法

  protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
if (e.Day.IsOtherMonth)
{
Style visible = new Style();
visible.BackColor = System.Drawing.Color.White;
visible.BorderColor = System.Drawing.Color.White;
visible.ForeColor = Color.White;
e.Day.IsSelectable = false;
e.Cell.ApplyStyle(visible);
return;
}
}

e.Day.IsSelectable = false;这句即是设置不可选择的方法

上一篇:【Ural】【1519】Formula 1


下一篇:模式窗口刷新不弹出新窗口触发NET事件