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())); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)