程序代码
protected void Calendar1_PreRender(object sender, EventArgs e)
{
Thread myThread = Thread.CurrentThread;
CultureInfo myClt = (CultureInfo)myThread.CurrentCulture.Clone();
myClt.DateTimeFormat.DayNames = new string[] { "Sun","Mon", "Tus", "Wes", "Thu", "Fri", "Sat" };
myClt.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
myThread.CurrentCulture = myClt;
}
{
Thread myThread = Thread.CurrentThread;
CultureInfo myClt = (CultureInfo)myThread.CurrentCulture.Clone();
myClt.DateTimeFormat.DayNames = new string[] { "Sun","Mon", "Tus", "Wes", "Thu", "Fri", "Sat" };
myClt.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
myThread.CurrentCulture = myClt;
}
2、记得把Calendar的DayNameFormat="Full" 默认是Short值,如果不改,是无法显示出来的。
效果如图:
3、如果需要给星期天加个背景,可在DayRender事件中添加
程序代码
//星期日添加背影颜色
if (e.Day.Date.DayOfWeek == DayOfWeek.Sunday)
{
e.Cell.BackColor = System.Drawing.Color.YellowGreen;
}
if (e.Day.Date.DayOfWeek == DayOfWeek.Sunday)
{
e.Cell.BackColor = System.Drawing.Color.YellowGreen;
}
4、给日期下方添加文字
程序代码
DateTime dt = new DateTime(2009, 6, 3);
if (e.Day.Date.Date == dt)
{
e.Cell.Controls.Add(new LiteralControl("<br>*"));
}
if (e.Day.Date.Date == dt)
{
e.Cell.Controls.Add(new LiteralControl("<br>*"));
}