Calendar HowTo: Add Multiple Events to a SINGLE day (c#)

Posted on 2008-11-16
Last Modified: 2013-12-17
How do I add MULTIPLE events to a SINGLE day using the calendar in C#. Code below (from my study guide) uses a Hashtable. But the hashtable requires a unique key. This seems to be a problem if multiple events happen on the same day.

I need a clue.

using System;

using System.Collections;

using System.Collections.Generic;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

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


    // create hash tables to hold values

    private Hashtable m_SchoolClosed = new Hashtable();


    protected void Page_Load(object sender, EventArgs e)


        m_SchoolClosed = new System.Collections.Hashtable();

        // populate a list of School Closings

        m_SchoolClosed.Add("11/27/2008", "Closed");

        m_SchoolClosed.Add("11/28/2008", "Closed");


    protected void Calendar1_SelectionChanged(object sender, EventArgs e)


        Label1.Text = Calendar1.SelectedDate.Date.ToShortDateString();


    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)


        if (m_SchoolClosed.ContainsKey(e.Day.Date.ToShortDateString()))


            if(!e.Day.IsOtherMonth && !e.Day.IsWeekend)


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

                e.Cell.Controls.Add(new LiteralControl("<br />" + m_SchoolClosed["11/27/2008"].ToString()));





Open in new window

Question by:the_sleeper
    LVL 14

    Accepted Solution

    Maybe instead of using a hash table you created your own class to store your details and store that in a collection.  Then for each day in the calendar, you grab all the classes with that date and add each one of those to the calendar.

    Or, you could have a collection of some sort, with each row being a key (the date) and the value being an array of the events for that day.  So as you access the key from the collection (the date) it then gives you an array of the events.  Then loop through that list of events adding each one to the calendar.

    Author Closing Comment

    Thanks jjardine,

    That's exactly what I am looking for: Strategy. Briefly of the two choices: which would you use and why?

    thanks again.
    LVL 14

    Expert Comment

    Well i am not sure which I would use.   The second option would make it easier to find the array of events because you can just use the date key in the hash to get them.  I say easier because the implementation is there for you.   In the first way you might have to do a bit more work to sort the collection of objects by Date or just create a new function to find each object with the matching date.  

    As far as performance, I am not sure which would be faster.  Possibly the hash if you are just storing an array of strings as the events in the value of the hash row.  The custom class might create more overhead than is needed.   A lot might depend on how many events you would be loading into your collection at any given time.  

    Author Comment

    Thanks Again, jjardine


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now