Calendar 控件的使用

<html>
<head>
    <script language="C#" runat="server">

        String [][] holidays;

        void Page_Load(Object Sender, EventArgs e) {

            holidays = new String[13][];

            for (int n=0; n<13 ;n++)
                    holidays[n] = new String[32];

            holidays[1][1]   = "New Year's Day";
              holidays[1][26]  = "Australia Day";
            holidays[2][2]   = "Groundhog Day";
            holidays[2][14]  = "Valentine's Day";
            holidays[3][17]  = "St. Patrick's Day";
            holidays[4][1]   = "April Fool's Day";
            holidays[5][1]   = "May Day";
            holidays[6][15]  = "My Birthday";
            holidays[7][15]  = "My Anniversary";
            holidays[8][15]  = "My Mother's Birthday";
            holidays[9][24]  = "Autumnal Equinox";
            holidays[12][26] = "Boxing Day";
        }

        void Calendar1_DayRender(object sender, DayRenderEventArgs e) {

            CalendarDay d = ((DayRenderEventArgs)e).Day;
            TableCell c = ((DayRenderEventArgs)e).Cell;

            if (d.IsOtherMonth) {
                c.Controls.Clear();
            }
            else {
                try {
                    string Hol = holidays[d.Date.Month][d.Date.Day];

                    if (Hol != string.Empty)
                        c.Controls.Add(new LiteralControl("<br>" + Hol));
                }
                catch (Exception exc) {
                    Response.Write (exc.ToString());
                }
            }
        }

        void Date_Selected(object s, EventArgs e) {
            Label1.Text = "Selected date is: " + Calendar1.SelectedDate.ToShortDateString();
        }

    </script>

</head>

<body>

    <h3><font face="Verdana">Adding Custom Content to Calendar</font></h3>
    <p><p>

    <form id="Form1" runat=server>

        <asp:Calendar id=Calendar1 runat="server"
            ondayrender="Calendar1_DayRender"
            onselectionchanged="Date_Selected"
            ShowGridLines="true"
           
            Font-Size="9px"
            Width="500px"
           
            TitleStyle-BackColor="Gainsboro"
            TitleStyle-Font-Size="12px"
            TitleStyle-Font-Bold="true"
            DayStyle-VerticalAlign="Top"
            DayStyle-Height="50px"
            DayStyle-Width="14%"
            SelectedDate="1/1/0001"
            SelectedDayStyle-BackColor="Navy"
            />

        <p>
        <asp:Label id=Label1 runat="server" />
    </form>

s

</body>
</html>
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值