I have an ASP.Net Calendar control that, on DayRender, loops through a list of "CalendarEvents" (one of my classes). If the day that DayRender is on is in the list of CalendarEvents, then fill that calendar cell with the details of the event.
In my test environment, there is no problem, but I imagine with thousands of records, it might become a problem. Here is what I'm doing:
public partial class calendar : System.Web.UI.Page
{
CalendarEventList allevents = CalendarEventManager.GetListAll();
//Page_Load, etc...
protected void calmaincalendar_DayRender(object sender, DayRenderEventArgs e)
{
foreach (CalendarEvent x in allevents)
{
if (e.Day.Date == x.EventDate)
{
//logic to extract the data from x, and modify the e.Cell to display that data
}
}
}
}
My questions are:
1) I'm putting the events as a page level variable, so that the database only needs to be called once, and not on every single DayRender. Good, bad? Potential issues? This page is purely to read the Calendar Events, not edit or delete.
2) Looping through the "allevents" list on every DayRender, is that potentially dangerous/resource intensive? Does the Calendar control call DayRender for just the month that's being displayed? If so, meaning only 30 or 31 calls at a time, it might be fine. But if it does something like calls DayRender for the entire year, or the previous and next months as well...Anyway, hopefully you get my point. Advice on this would be appreciated.
3) Is there anything that I could be doing better? I realize I only posted the bare skeleton, but if anyone has any similar experience, or pitfalls they wished they had realized earlier, that advice would be appreciated.
As I was typing up the questions I realized that when I get the CalendarEventList at the page level, I could immediately loop through it and cut out everything except for the last 3 and future 3 months or something. Problem there is, somehow keeping track of it so that when the user goes back 4 months, I'd have to realize this and call the database again. I have a vague feeling that the answer is somewhere in that direction, but still not sure.
As you talk about records I guess you have an underlying database. If so, I will suggest to create a query for that, so you can do this:
foreach (CalendarEvent x in CalendarEventManager.GetForDate(e.Day.Date))
{
//logic to extract the data from x, and modify the e.Cell to display that data
}
This way, you will retrieve just the needed records.