微软官方地址 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;这句即是设置不可选择的方法