2012-02-09 32 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())并检查你得到的错误:)

相关问题