Calendar Control and Loops

G

Greg Ellis

I'm trying to find a way to loop through the Calendar Control and add
business days next to each day in the calendar after the SelectedDate.
Example: if a user selects May 2nd 2005, I want the calendar to display
|3-1|, |4-2|, |5-3|...etc.
I created a loop to display this. However, the loop is running first before
rendering it.
It looks like |3-1-2-3-4-5|, |4-1-2-3-4-5|, |5-1-2-3-4-5|...etc.

I currently have the loop set from 1 to 5, but once I get this working it
will be set from 1 to 90.

private void calWorkDays_DayRender(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)

{

for(int x = 1; x < 6; x++)

{

e.Cell.Controls.Add(new LiteralControl(" - " +
x.ToString()));


}

}



I have code that bypasses weekends and holidays. that all works fine. It's
this loop that's killing me. I have tried everything I can think of to get
this to work. I was thinking that a "foreach" might do the trick, but I
can't get the syntax right with it.

any help would greatly be appreciated,

thanks.
 
S

Scott Allen

Hi Greg:

Remember, DayRender fires once for each day in the calendar. You
wouldn't want to loop each time DayRender fires, what you need is a
counter.

int businessDaycounter = 1; // declare this at class scope

Each time DayRender fires you just need to write out the counter with
a LiteralControl as you have done, and then increment the counter (add
one). No looping needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,198
Latest member
JaimieWan8

Latest Threads

Top