2012-02-09 88 views
0

我想顯示日曆,其中包含我存儲在數據庫中的一些註釋/事件。 在某些日期添加了多個筆記。在日曆的同一日期顯示多個註釋

現在當頁面加載時,我希望所有在我的日曆控件。

我做到了,但它只在日曆中顯示一個(第一次輸入)音符,儘管我在同一日期保存了多個音符。

它看起來像下面的圖片.. enter image description here

在這種影像在日期7,我增加2注,但只顯示一個...

我的代碼如下...

public partial class _Default : System.Web.UI.Page 

{ 

    public static ArrayList MyColllection; 

    //Structure 

    public struct My_Date 

    { 

     public DateTime Cal_Date; 

     public string Cal_Type; 

     public string Cal_Title; 

    } 

    protected void Page_Load(object sender, EventArgs e) 

    { 

     if (!Page.IsPostBack) 

     { 

      MyColllection = Get_Event(); 

     } 

    } 

    public ArrayList Get_Event() 

    { 

     SqlConnection myCon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); 

     SqlCommand myComd = new SqlCommand("SELECT * FROM Cal_Event",myCon); 

     SqlDataReader myDataReader; 

     try 

     { 

      myCon.Open(); 

      myDataReader = myComd.ExecuteReader(); 

      MyColllection = new ArrayList(); 

      My_Date temp; 

      //Iterate through the data reader 

      while(myDataReader.Read()) 

      { 

       temp.Cal_Title = myDataReader.GetValue(1).ToString(); 

       temp.Cal_Date = Convert.ToDateTime(myDataReader.GetValue(2)); 

       temp.Cal_Type = myDataReader.GetValue(3).ToString(); 

       MyColllection.Add(temp); 

      } 

     } 

     catch 

     {} 

     finally 

     { 

      myCon.Close(); 

     } 

     return MyColllection; 

    } 

    public void Calendar1_DayRender(object o, DayRenderEventArgs e) 

    { 

     string FontColor; 

     string compDate = "01/01/1900"; // Date to compare initially 

     DateTime DayVal = Convert.ToDateTime(compDate); 

     bool mItemDay = false; 

     bool dayTextChanged = false; 

     StringBuilder strTemp = new StringBuilder(); 

     foreach (My_Date temp_dt in MyColllection) 

     { 

      if ("01/01/1900" != temp_dt.Cal_Date.ToShortDateString()) 

      { 

       if (dayTextChanged == true) 

       { 

        break; 

       } 

       mItemDay = false; 

       DayVal = temp_dt.Cal_Date; 

      } 

      else 

      { 

       mItemDay = true; 

      } 

      if (e.Day.Date == Convert.ToDateTime(temp_dt.Cal_Date.ToString("d"))) 

      { 

       switch (temp_dt.Cal_Type) 

       { 

        case "1" : 

         FontColor = "Blue"; 

         break; 

        case "2": 

         FontColor = "Red"; 

         break; 

        default: 

         FontColor = "Black"; 

         break; 

       } 

       if (mItemDay == false) 

       { 

        strTemp = new StringBuilder(); 

       } 

       else 

       { 

        strTemp.Append("<br>"); 

       } 

       strTemp.Append("<span style='font-family:verdana;font-size:10px;font-weight:bold;color'"); 

       strTemp.Append(FontColor); 

       strTemp.Append("'><br>"); 

       strTemp.Append(temp_dt.Cal_Title.ToString()); 

       strTemp.Append("</span>"); 

       e.Cell.BackColor = System.Drawing.Color.Yellow; 

       dayTextChanged = true; 

      } 

     } 

     if (dayTextChanged == true) 

     { 

      e.Cell.Controls.Add(new LiteralControl(strTemp.ToString())); 

     } 

    } 

} 

所以我需要在同一天顯示多個註釋...

所以我該怎麼做?

在此先感謝....

回答

1

日曆基本上日期選擇器,並用它們來顯示數據是最常見的錯誤的人做一個。使用ListView來顯示你的數據/事件;日曆從來不是爲了那個。

在某個階段,日曆單元格將隨着事件在同一天添加而展開,從而打破整個顯示。如果你嘗試設置一個限制,那麼人們會抱怨,並開始質疑爲什麼其他事件列出,他們不是,等等。

在你的代碼中,你基本上是吞嚥異常,而不是處理它。註釋掉try-catch-finally(離開Close())並檢查你得到的錯誤:)

相關問題