Hiding non month days in the ASP.NET Calendar control

I had given up on this one until I discovered an insanely easy solution.

To hide days not in the focussed month of the ASP.NET Calendar control you need to handle the Calendar control’s DayRender event. By quizzing the passed in DayRenderEventArgs you can determine whether the day is in the current month and simply set that day’s text to “” if it isn’t.

protected void myCalendar_DayRender(object sender, DayRenderEventArgs e) {
if (e.Day.IsOtherMonth) {
e.Cell.Text = “”;
}
}

Simple :)

And the intuitive amongst you will have figured that you can do all kinds of neat stuff on a day by day basis as the control is rendered.

Advertisements

8 thoughts on “Hiding non month days in the ASP.NET Calendar control

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s