ASP.net page with multiple calendar controls

I have an asp.net 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.
LVL 1
countrymeisterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Corey HabbasSecurityCommented:
I am including sample code from an online article about how to set up a single calendar control:
http://www.c-sharpcorner.com/uploadfile/sd_patel/aspnetcalendarcontrol11222005054337am/aspnetcalendarcontrol.aspx

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

MikeQcCommented:
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

countrymeisterAuthor Commented:
MikeQc:
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
MikeQcCommented:
Ok, so assuming your Calendars are named Calendar1, Calendar2...
protected void Page_Load(object sender, EventArgs e)
        {
            DateTime startDate = DateTime.Today;
            for (int i = 0; i < 12; i++)
            {
                Calendar c = (Calendar)Page.FindControl("Calendar" + i.ToString());
                c.VisibleDate = startDate.AddMonths(i);
            }
        }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.