[RESOLVED] [2005] Calendar selected date colours
Hello,
I'm currently experimenting with the calendar control, and have created a page showing monthly calendars from January 2008, through to January 2009.
I've done this, rightly or wrongly, by dragging the individual calendar tool from the toolbar onto the page, and have named all 13 of them by their respective month names. I don't know if this is the best way to do this.
The VisibleDate is always the first of the month so that the correct month is displayed.
What I want to do then is highlight each public holiday with a given color. To do this, I've created an array of public holidays, and I want to iterate through the array, and highlight the dates accordingly. Iterating through the array is fine, but I don't know how to do it so that it references the correct calendar to work with.
Next, using some code that I've written in VB.NET, I want to identify two other key dates in each month, and colour those dates with a different colour.
Any advice or code snippets would be appreciated.
Re: [2005] Calendar selected date colours
You seem to be doing fine so far, although personally I would render all 13 in a loop myself, probably using a repeater control so that I can control how many are rendered. But that's for later.
Your immediate question is about the holidays. So if you've got your array of public holidays, you must have two 'fields': month and day. Handle your calendar's... rather, handle each calendar's DayRender event. Then check the value of e.Day.Date.
If e.Day.Date is in your array, then e.Cell.ApplyStyle(), where you pass in the name of a CSS class.
Re: [2005] Calendar selected date colours
Thanks for your reply.
I was hoping that I'd be able to iterate through the array of holiday dates, and test for conditions like, if the month = 1, then work with Me.January, select the holiday day in January, and apply some colour formatting to that particular day.
I didn't really want to have to specifically handle 13 events that would be doing pretty much the same thing. It just seems a long-winded way of doing it .... unless I have a go at working with the repeater that you've mentioned.
Would the repeater be a better way of doing what I want?
Re: [2005] Calendar selected date colours
You can get one method to handle 13 events. Because you can get the month and date out from the eventargs e, you can compare to the entire array, no problem.
Yes, a repeater may make things easier as you're putting all your logic in fewer places. You will handle the Repeater's ItemCommand event, assuming the calendar does bubble its DayRender event up! And if it doesn't, you can assign a method to do it, which brings you back to the answer in the previous paragraph.
Re: [2005] Calendar selected date colours
Many thanks for your advice.
I avoided using the repeater, and using the DayRender event for each calendar event works fine.
Re: [RESOLVED] [2005] Calendar selected date colours
Good to know, but eventually you'll learn to use the Repeater ;)