I need to display a calendar that shows all the months of an year. In
that, I need to show different colors for certain events. I know how to
display a calendar for a certain month but I am not sure if there is a way
to
display all the months of an year? Please let me know.
This is easy enough using the calendar control (actually, 12 calendar
controls), maybe arranged in a convenient 3 x 4 grid.
1) In the page's ViewState, store the first day of the first calendar
2) Create 12 calendar controls in the HTML portion of your ASPX page - call
them something like 'cal0', 'cal1', 'cal2' etc
<asp:Calendar ID="cal0" OnDayRender="DayRender" runat=server
ShowNextPrevMonth="false" OtherMonthDayStyle-ForeColor="DarkGray"><DayStyle
Font-Size="XX-Small" /><DayHeaderStyle Font-Size="XX-Small"
/></asp:Calendar>
3) Set the date of the first calendar to whatever you want your starting
date to be, maybe the current date, e.g.
cal0.TodaysDate = DateTime.Now;
cal0.VisibleDate = DateTime.Now;
4) Increment the starting date of each subsequent calendar e.g.
cal1.VisibleDate = cal0.VisibleDate.AddMonths(1);
cal2.VisibleDate = cal1.VisibleDate.AddMonths(1);
etc
5) In your code-behind, retrieve all the events which fall between the first
day of the first calendar and 365 days in advance of that date, and store
them in a Hashtable
6) Create a method called DayRender, as follows:
public void DayRender(object source, DayRenderEventArgs e)
{
if (htblDates.ContainsKey(e.Day.Date.ToString("dd MMM yyyy")) &&
!e.Day.IsOtherMonth)
{
e.Cell.Font.Bold = true;
}
}
There are loads of other things you can do - you could change the day's
background colour, add text underneath it etc, but the above should be
enough to get you started.