Display Custom Data In An ASP:Calendar Cell
10/19/2007 3:41:24 AM
Pretty basic stuff but can be very useful. I've been working lately on a scheduling application (2.0) and just finished a user welcome screen at about 1:00am on this lovely Thursday night. The idea is that users login to the system and on their homepage are shown a calendar. This calendar should show the current month (or selected month) and visually display what days the user is scheduled for a certain task. The dates are entered by administrators and stored in a SQL 2005 database.
There are two important methods to use: OnDayRender and OnVisibleMonthChanged.
85% complete pseudo-code. The accountNumber is arbitrary. What you don't see is the calendar control in my .aspx page wired up to these handlers.
List<DateTime> _dates = new List<DateTime>();
protected void Page_Load(object sender, EventArgs e)
_dates = Schedule.GetDates(accountNumber, calendar.TodaysDate);
protected void OnDayRender(object sender, DayRenderEventArgs e)
e.Cell.BackColor = Color.CornflowerBlue;
protected void MonthChanged(object sender, MonthChangedEventArgs e)
_dates = Schedule.GetDates(accountNumber, e.NewDate);
Now when the user clicks the next and previous month links a new list of dates will be populated and the calendar will display accordingly.
This is very basic stuff but highly effective. The current application I'm working on displays / functions far beyond the quick demo screenshot I posted. I give users the ability drill down from the calendar day (SelectionChanged) to view a more detailed view of the current task. Users can even switch tasks with another user or post up a task to be taken over by someone else. Think trading and picking up shifts at a restaurant.
If there is an easier way to accomplish this please let me know.