A client of mine asked me if I could build an report that would replace the wall calendar they use to visually keep track of upcoming employee vacations. The vacations are kept entered into their VB6 application that I wrote for them years ago. But they wanted a report that really looked like a calendar. Since they also have a web portal that is used internally and externally, I thought I would do this in ASP.NET rather than add it to the VB app, since all of their custom software pulls out of a common SQL database.
Though I had used the familiar calendar controls in Windows and ASP.NET frequently,
to render

it wasn't what I was looking for. As far as I knew, that was only for clicking on to select dates to do something else with. So I looked all over the internet for a control that would display something more like a wall calendar with space for more information. And looked and looked... The problem was that I didn't know what I was looking for. When I finally saw an example of what I was looking for here and boy, did I feel like a dope.
The solution was right in the standard asp.net calendar control! By resizing the darned thing, you suddenly get a pallete on which you can put other html!

So all I had to do was work with the DayRender event of the calendar.
I started outo with a simple test where if the value of current date was equal to '12/25/2006', then I inserted the word “Christmas“ into the calendar. With that grand success, I was ready to put my client data on the control.
I have a DataTable (_tDates) in memory that is repopulated each time the user moves to a new month. As the calendar renders out the month, the DayRender event is hit for each date. I filter the table on that date, iterate through any results and then render some additional text into the cell for the day being rendered. First I list the # of techs that are off on that day, then I list the name of the tech and the reason they are off. All of this is done using literal controls.
Here's a sample
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
'get text for this date
Dim techcount As Int32
Dim dv As DataView = _tDates.DefaultView
dv.RowFilter = "startdate>='" & e.Day.Date & "' and enddate<='" & e.Day.Date & "'"
If dv.Count > 0 Then
techcount = dv.Count
e.Cell.Controls.Add(New LiteralControl("
(" & techcount.ToString & ")
"))
Dim sb As New StringBuilder
For i As Int32 = 0 To dv.Count - 1
sb.AppendLine("" & dv(i)("employee") & " : " & dv(i)("reason") & "
")
Next
e.Cell.Controls.Add(New LiteralControl("
" & sb.ToString & "
"))
End If
End Sub
Here is a slice of the resulting calendar, and since I was too lazy to redo this against fake data, I have just blocked out the names of the truly vacationing employees. Naturally this is on an AJAX enabled site so that when the user goes from month to month, it's sooooper smooooth.