Asp.net 在日历的同一日期显示多个注释

Asp.net 在日历的同一日期显示多个注释,asp.net,Asp.net,我想用我存储在数据库中的一些笔记/事件显示日历。 在某些日期,会添加多个注释 现在,当页面加载时,我希望所有这些都在我的日历控件中 我这样做了,但它只显示日历中的一个(第一次输入)注释,尽管我在同一日期保存了多个注释 如下图所示。。 在第7天的这张图片中,我添加了2个注释,但它只显示了一个 我的代码如下 public partial class _Default : System.Web.UI.Page { public static ArrayList MyColllection

我想用我存储在数据库中的一些笔记/事件显示日历。 在某些日期,会添加多个注释

现在,当页面加载时,我希望所有这些都在我的日历控件中

我这样做了,但它只显示日历中的一个(第一次输入)注释,尽管我在同一日期保存了多个注释

如下图所示。。

在第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()));

        }

    }

}
public分部类\u默认值:System.Web.UI.Page
{
公共静态数组列表mycollection;
//结构
公共结构我的日期
{
公共日期时间校准日期;
公共字符串CALU类型;
公共字符串CALU标题;
}
受保护的无效页面加载(对象发送方、事件参数e)
{
如果(!Page.IsPostBack)
{
mycollection=Get_Event();
}
}
公共ArrayList Get_事件()
{
SqlConnection myCon=新的SqlConnection(ConfigurationManager.AppSettings[“ConnectionString”]);
SqlCommand myCmd=新的SqlCommand(“从校准事件中选择*”,myCon);
SqlDataReader-myDataReader;
尝试
{
myCon.Open();
myDataReader=myCmd.ExecuteReader();
mycollection=newarraylist();
我的约会时间;
//遍历数据读取器
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();
mycollection.Add(temp);
}
}
抓住
{}
最后
{
myCon.Close();
}
返回mycollection;
}
公共无效日历1_DayRender(对象o、DayRenderEventArgs e)
{
字符串颜色;
字符串compDate=“01/01/1900”;//最初比较的日期
DateTime DayVal=Convert.ToDateTime(compDate);
bool-mItemDay=false;
bool dayTextChanged=false;
StringBuilder strTemp=新的StringBuilder();
foreach(我的选择中的日期和温度)
{
如果(“01/01/1900”!=temp\u dt.Cal\u Date.ToSortDateString())
{
如果(dayTextChanged==true)
{
打破
}
mItemDay=假;
DayVal=临时校准日期;
}
其他的
{
mItemDay=true;
}
如果(e.Day.Date==Convert.ToDateTime(temp\u dt.Cal\u Date.ToString(“d”))
{
开关(温度校准型)
{
案例“1”:
FontColor=“蓝色”;
打破
案例“2”:
FontColor=“红色”;
打破
违约:
FontColor=“黑色”;
打破
}
如果(mItemDay==false)
{
strTemp=新的StringBuilder();
}
其他的
{
strTemp.追加(“
”); }
strTemp.Append(“日历基本上是日期选择器,使用它们来显示数据是人们最常犯的错误之一。使用列表视图来显示数据/事件;日历从来就不是用来显示数据/事件的

在某个阶段,日历单元格会随着当天事件的添加而拉伸,破坏整个显示。如果你试图设置一个限制,那么人们会抱怨,并开始询问为什么其他事件会被列出,而他们的没有,等等

在代码中,您基本上是在吞咽异常而不是处理异常