This tip talks about one interesting customization of ASP.NET Calendar Control. Calendar control provides members like SelectedDayStyle
, WeekendDayStyle
, TodayDayStyle
to apply the styles for specific dates. Let’s consider a situation where, you need highlight the current week with some different color. ASP.NET Calendar control
does not provides any direct styles for the current week selection when your selection mode is date only. Let’s have a look how to deal with that.
First of all we have to find out the current week start date and end date. We can have different logic to implement the same. Here is how I have putted in simple steps,
startOfWeek
represent the Week Start Date and endOfWeek
represent Week End Date. Here, I have consider Week start day as Sunday ( DayofWeek.Sunday
).
Once we have the Week start Date and Week End Date, we are pretty good to do some logic in Calendar control DayRender
Event. DayRender
events in ASP.NET Calendar control is extremely powerful. This can help to customize the calendar control at max level.
Below image shows the resulting calendar displays
If you look at the code snippet for DayRender event, I have used
This will highlight the the date with the same Selected Day Style which falls under current week, other wise you will get the same color ( Lightgreen for the selected date with in the current week )
I did this while answering a question at Code Project Q&A forum, http://bit.ly/p9sBgw
Hope this helps !
Cheers !
Abhijit