Datasheet

Viewing the Online Calendar
The DiaryMain.aspx page is the central hub of the application. It displays a calendar of the current
month, showing which days have events or diary entries associated with them. It also displays a list of
upcoming events and diary entries for the current month.
To display when a day has events or a diary entry, the
OnDayRender event of the Calendar control
is used:
Protected Sub Calendar1_OnDayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
If Not e.Day.IsOtherMonth Then
If entryArrayOfDays Is Nothing Then
entryArrayOfDays = GetDaysInMonthWithEntries(Session(“DiaryId”),
e.Day.Date.Month, e.Day.Date.Year)
End If
If eventArrayOfDays Is Nothing Then
eventArrayOfDays = GetDaysInMonthWithEvents(Session(“DiaryId”),
e.Day.Date.Month, e.Day.Date.Year)
End If
If entryArrayOfDays(CInt(e.Day.DayNumberText)) Then
e.Cell.BackColor = Drawing.Color.Blue
End If
If eventArrayOfDays(CInt(e.Day.DayNumberText)) Then
e.Cell.ForeColor = Drawing.Color.Red
End If
End If
End Sub
The first If block in the preceding event code deals with ensuring entryArrayOfDays and
eventArrayOfDays are populated with details of which days have an associated event or diary entry.
They are both Boolean arrays; if a day has an event or entry, the array element for that day contains
True. Arrays are populated by the DiaryEnty and DiaryEvent classes’ shared functions
GetDaysInMonthWithEntries() and GetDaysInMonthWithEvents().
In the second
If block of the event the code checks to see whether the day of the month being rendered
has a diary event or diary entry. If there’s an event, the day’s text is set to red. If there’s a diary entry the
day’s background is rendered in blue.
As well as a
Calendar control, the main page also has two GridView controls (discussed a bit later).
The upper one displays upcoming events; the lower one displays recent diary entries. Both
GridView
controls get their data from an ObjectDataSource control, new to ASP.NET 2.0. In the past, data source
controls have interacted directly with the database. They are nice and easy to use put on one a page,
set a few properties, drop in a few data-aware controls, and away you go. However, that’s not actually
good coding practice. Splitting up the data access, business, and presentation layers is generally consid-
ered good practice, but means leaving behind nice and easy-to-use data source controls.
24
Chapter 1
04_749516 ch01.qxp 2/10/06 9:11 PM Page 24