<%@ Page language="c#" AutoEventWireup="True" %>
<HTML>
	<HEAD>
		<TITLE>第5章_高级Web控件 如何在Calendar日期选择器控件中自定义个别日</TITLE>
		<script language="C#" runat="server">
		
		// 创建日期数组
		protected String [,] array = new String[13,32];
		
		void Page_Load(object sender, System.EventArgs e)
		{
			// 自定义节假日或者其它信息
			array[1,1] = "元旦";		// 数组[1,1]代表1月1日
			array[2,14] = "情人节";
			array[2,18] = "我的生日";	// 自定义的信息
			array[3,8] = "妇女节";
			array[5,1] = "劳动节";
			array[7,1] = "建党节";
			array[8,1] = "建军节";
			array[10,1] = "国庆节";
		}
		
		void MyCalendar_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
		{
			// 以红色背景定制周末日的外观
			if ( e.Day.IsWeekend )
			{
				e.Cell.BackColor = System.Drawing.Color.Red;
			}

			// 判断是否节假日，显示相应的节假日信息
			int month,day;
			month = e.Day.Date.Month;
			day = e.Day.Date.Day;
			if ( array[month, day] != null)
			{
				Label label = new Label();
				label.Text = "<br>" + array[month, day];
				e.Cell.Controls.Add(label);			
			}
		}
		
		</script>
	</HEAD>
	<body>
		<form id="Form1" runat="server">
			<h3>如何在Calendar日期选择器控件中自定义个别日</h3>
			<FONT face="宋体">以红色背景显示周末<BR>
				显示节假日信息</FONT>
			<BR>
			<asp:Calendar id="MyCalendar" runat="server" OnDayRender="MyCalendar_DayRender" ShowGridLines="True">
				<SelectedDayStyle ForeColor="Black" BackColor="Yellow" Font-Bold="True"></SelectedDayStyle>
			</asp:Calendar>
			<BR>
		</form>
	</body>
</HTML>
