ASP.NET2.0中Calendar的使用(添加自己的日期備忘)

來源:互聯網
上載者:User

一直以來我不太喜歡使用.net裡的Calendar控制項.主要是因為他每點擊一次都會重新整理.隨著AJAX.NET的推出這個控制項也有了一絲的用處.所以也就研究一下

using System;using System.Data;using System.Configuration;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 _Default : System.Web.UI.Page {    //聲明一個數組放置對應的節日    //為了使用方便定義的是13月,32天    string[,] days=new string[13,32];    protected void Page_Load(object sender, EventArgs e)    {        days[1, 1] = "元宵節";    }    protected void Button1_Click(object sender, EventArgs e)    {            }    /// <summary>    /// 編寫DayRender事件    /// </summary>    /// <param name="sender"></param>    /// <param name="e"></param>    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)    {        CalendarDay d = e.Day;//得到目前的儲存格的日期資訊        TableCell c = e.Cell;//得到儲存格        if (d.IsOtherMonth)//判斷如果不是本月的則把儲存格內的內容清空        {            c.Controls.Clear();        }        else        {            string myday=days[d.Date.Month,d.Date.Day];            if (myday!=null)//如果有相關日期就.....            {                c.Controls.Clear();//可以清除以後再添加自己的控制項                Button b = new Button();                b.Text="a";                c.Controls.Add(b);//例如我這裡添加的是一個按鈕.把原來的1號給幹掉了.orz                c.Controls.Add(new LiteralControl("<a title='"+myday+"'>★</a>"));                c.ForeColor = System.Drawing.Color.Red;//然後還可以添加一些儲存格的內容            }        }    }}

運行效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.