asp.net2.0里用Calendar控件做带节日提示的日历
2007-12-06 15:37
411 查看
1、建立网页CalendarThree.aspx,代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CalendarThree.aspx.cs" Inherits="CalendarThree" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender" Height="206px" Width="369px"></asp:Calendar>
</div>
</form>
</body>
</html>
2、CalendarThree.aspx.cs代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class CalendarThree : System.Web.UI.Page
{
String[][] holidays = new String[13][];
protected void Page_Load(object sender, EventArgs e)
{
for (int n = 0; n < 13; n++)
holidays
= new String[32];
holidays[1][1] = "元旦";
holidays[2][14] = "情人节";
holidays[3][8] = "妇女节";
holidays[3][12] = "植树节";
holidays[4][1] = "愚人节";
holidays[5][1] = "劳动节";
holidays[5][4] = "青年节";
holidays[5][12] = "护士节";
holidays[5][14] = "母亲节";
holidays[5][14] = "助残日";
holidays[6][1] = "国际儿童节";
holidays[6][5] = "环境保护日";
holidays[6][18] = "父亲节";
holidays[6][26] = "国际禁毒日";
holidays[7][1] = "中共诞辰";
holidays[8][1] = "建军节";
holidays[9][10] = "教师节";
holidays[10][1] = "国庆节";
holidays[11][23] = "感恩节";
holidays[12][1] = "艾滋病日";
holidays[12][12] = "西安事变";
holidays[12][25] = "圣诞节";
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
CalendarDay d = ((DayRenderEventArgs)e).Day;
TableCell c = ((DayRenderEventArgs)e).Cell;
if (e.Day.IsOtherMonth)
{
e.Cell.Controls.Clear();
}
else
{
try
{
string Hol = holidays[e.Day.Date.Month][e.Day.Date.Day];
if (Hol != string.Empty)
e.Cell.Controls.Add(new LiteralControl("<br><font color=blue size=2>" + Hol + "</font>"));
}
catch (Exception exc)
{
Response.Write(exc.ToString());
}
}
}
}
3、运行的效果如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CalendarThree.aspx.cs" Inherits="CalendarThree" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender" Height="206px" Width="369px"></asp:Calendar>
</div>
</form>
</body>
</html>
2、CalendarThree.aspx.cs代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class CalendarThree : System.Web.UI.Page
{
String[][] holidays = new String[13][];
protected void Page_Load(object sender, EventArgs e)
{
for (int n = 0; n < 13; n++)
holidays
= new String[32];
holidays[1][1] = "元旦";
holidays[2][14] = "情人节";
holidays[3][8] = "妇女节";
holidays[3][12] = "植树节";
holidays[4][1] = "愚人节";
holidays[5][1] = "劳动节";
holidays[5][4] = "青年节";
holidays[5][12] = "护士节";
holidays[5][14] = "母亲节";
holidays[5][14] = "助残日";
holidays[6][1] = "国际儿童节";
holidays[6][5] = "环境保护日";
holidays[6][18] = "父亲节";
holidays[6][26] = "国际禁毒日";
holidays[7][1] = "中共诞辰";
holidays[8][1] = "建军节";
holidays[9][10] = "教师节";
holidays[10][1] = "国庆节";
holidays[11][23] = "感恩节";
holidays[12][1] = "艾滋病日";
holidays[12][12] = "西安事变";
holidays[12][25] = "圣诞节";
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
CalendarDay d = ((DayRenderEventArgs)e).Day;
TableCell c = ((DayRenderEventArgs)e).Cell;
if (e.Day.IsOtherMonth)
{
e.Cell.Controls.Clear();
}
else
{
try
{
string Hol = holidays[e.Day.Date.Month][e.Day.Date.Day];
if (Hol != string.Empty)
e.Cell.Controls.Add(new LiteralControl("<br><font color=blue size=2>" + Hol + "</font>"));
}
catch (Exception exc)
{
Response.Write(exc.ToString());
}
}
}
}
3、运行的效果如下:
相关文章推荐
- asp.net2.0里用Calendar控件做带节日提示的日历
- asp.net2.0里用Calendar控件做带节日提示的日历
- 跟我做:Javascript 下的日历控件(Calendar)
- 2-13 monthCalendar日历控件
- 修改Calendar(梅花雨)日历控件 兼容IE9 谷歌 火狐
- Flex中利用firstDayOfWeek属性改变DateChooser控件日历(calendar)布局的例子
- 日历控件推介之:Dynarch.com Calendar
- fullcalendar日历控件知识点集合
- Calendar日历控件多个日期的选择
- 日历控件Calendar的使用
- fullcalendar日历控件集合知识
- 网页日历显示控件calendar3.1
- FullCalendar日历控件使用小结
- Asp.net完美日历控件,支持FireFox,IE7(AjaxControlToolKit.Calendar)中文版
- ASP.NET Calendar日历(日期)控件使用方法
- fullcalendar日历控件知识点集合
- Discuz!NT控件剖析 之 ColorPicker(颜色拾取) 和Calendar(日历) [原创: 附源码]
- VS2.0控件之日历《Calendar》C#
- Discuz!NT控件剖析 之 ColorPicker(颜色拾取) 和Calendar(日历) [原创: 附源码]
- ASP.net下的前台日历控件源代码(不刷新页面)Calendar .js