天天看點

編寫帶有節日的月曆

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[n] = 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());

}

本文轉自蓬萊仙羽51CTO部落格,原文連結:http://blog.51cto.com/dingxiaowei/1366649,如需轉載請自行聯系原作者

繼續閱讀