ASP Calendar

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

How do you get rid of the days of the month that are not
in the month selected in a calendar control? For
example, I have a calendar control that shows November,
at the beginning and end of the calendar you can see the
end of October and the first few days of December. All I
want is November. Any ideas?

Greg
 
Greg,
the asp:Calendar control has a DayRender method - you can provide the
implementation for this. Specify it like this:

<asp:Calendar runat="server" id=Calendar1
onSelectionChanged="Calendar1_DateSelected"
onVisibleMonthChanged="Calendar1_MonthChanged"
onDayRender="Calendar1_DayRender"
...

Within the DayRender method you can decide how you want to render each day.
So I suggest you examine the calendar day and suppress rendering if it's the
wrong month.
Eg,

void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{

CalendarDay d = e.Day;
TableCell c = e.Cell;
c.Controls.Clear(); // remove the default rendering!
if (d.IsOtherMonth) return; // render nothing if it is the wrong month
...
}

here's the doc for the method:
http://msdn.microsoft.com/library/e...IWebControlsCalendarClassOnDayRenderTopic.asp

-Dino
 
Back
Top