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

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.

thanks
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

the_sleeperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jjardineCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
the_sleeperAuthor Commented:
Thanks jjardine,

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

thanks again.
0
jjardineCommented:
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.  
0
the_sleeperAuthor Commented:
Thanks Again, jjardine

sleeper
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.