Click here to Skip to main content
15,921,452 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to display calendar with some notes/events which i stored in database.
In some date more than one notes are added.

Now when page is load i want that all in my calendar control.

I done that BUT It displays only one(1st entered) note in the calendar although i saved more than one notes on that same DATE.

My code is as below...


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

           }

       }

   }



So I need to display multiple Notes on same day...

So How can I do this??


Thanks in Advance....
Posted

1 solution

This is a lot of code. Which line sets the note ? It must be showing only one, so you need instead to iterate over and concatenate all the value for the day, and show that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900