Link to home
Create AccountLog in
Avatar of countrymeister

asked on page with multiple calendar controls

I have an page with 12 calendar controls. I need to show on page load the current month and the remainder of the 11 months for the calendar controls.

Can someone let me know (source code examples) which owuld be the best way to do this.
Avatar of Corey Habbas
Corey Habbas
Flag of United States of America image

I am including sample code from an online article about how to set up a single calendar control:

So basically then you can alter the code to loop through the months.  The algorythm would be:
1) get the current month and year
2) render the calendar (as seen in the  sample code from the above link)
3) increment the month and render the next month's calendar

I agree a loop would be nicer...
But, this works.
protected void Page_Load(object sender, EventArgs e)
            Calendar1.VisibleDate = DateTime.Today;
            Calendar2.VisibleDate = Calendar1.VisibleDate.AddMonths(1);
            Calendar3.VisibleDate = Calendar2.VisibleDate.AddMonths(1);
            Calendar4.VisibleDate = Calendar3.VisibleDate.AddMonths(1);
            Calendar5.VisibleDate = Calendar4.VisibleDate.AddMonths(1);
            Calendar6.VisibleDate = Calendar5.VisibleDate.AddMonths(1);
            Calendar7.VisibleDate = Calendar6.VisibleDate.AddMonths(1);
            Calendar8.VisibleDate = Calendar7.VisibleDate.AddMonths(1);
            Calendar9.VisibleDate = Calendar8.VisibleDate.AddMonths(1);
            Calendar10.VisibleDate = Calendar9.VisibleDate.AddMonths(1);
            Calendar11.VisibleDate = Calendar10.VisibleDate.AddMonths(1);
            Calendar12.VisibleDate = Calendar11.VisibleDate.AddMonths(1);

Open in new window

Avatar of countrymeister


Please note that the add months needto be incremented accordingly

Example for calendar no three  the add months integer should be 2
for calendar number 4 the add months should be 3 and so on.

I was trying to see if there was abetter way to do this
Avatar of MikeQc
Flag of Canada image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account