Calendar控件使用方法 (二)

爲Calendar加額外信息:

   爲Calendar加額外信息,須要在Calendar控件初始化完成,但尚未呈現的時候來作,因此,用其DayRender事件,但事先,須要用數組將要加的信息準備好,放在Paged_Init函數中: 數組

           private string[][] arr;
           //初始化日曆控件中的節日
             arr = new string[13][];
           for (int i = 1; i < 13; i++)
           {
               arr[i] = new string[32];
           } 函數

           arr[1][1] = "元旦節";
           arr[1][15] = "元宵節";
           arr[2][14] = "情人節";
           arr[3][8] = "婦女節";
           arr[4][15] = "外國節";
           arr[5][1] = "勞動節";
           arr[5][5] = "端午節";
           arr[6][1] = "兒童節";
           arr[7][7] = "七夕節";
           arr[8][1] = "建軍節";
           arr[9][10] = "教師節";
           arr[10][1] = "國慶節";
           arr[12][25] = "聖誕節";
而後,在DayRend事件中,根據數組所表示的所在月和天的信息是否爲空,將信息設置好: spa

       protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
       {//初始化後,呈現以前激發
           CalendarDay d = e.Day;
           TableCell c = e.Cell;
           if (d.IsOtherMonth)
           {
               c.Controls.Clear();
           }
           else
           {
               try
               {
                   string txt = arr[d.Date.Month][d.Date.Day];
                   if (txt != String.Empty)
                   {
                       string day = d.Date.ToShortDateString();
                       c.Controls.Add(new LiteralControl("<br/><a href = 'http://user.qzone.com/157422192/" + day + "'><b>" + txt + "</b></a>"));
                       //c.Controls.Add(new LiteralControl("<br>" + txt));
                   }
               }
               catch (System.Exception ex)
               {
                   Response.Write(ex.ToString());
               }
           }
       } 事件

相關文章
相關標籤/搜索