Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp:calendar 1

Status
Not open for further replies.

figler

Programmer
Dec 26, 2001
155
US
I'm using the calendar web server control in a scheduling app.

Basically: user clicks on a date, and a list of the day's activities show up to the right of the control.

Well, I thought it would be nice if the calendar indicated which days were scheduled. To do this, I add all the days with activities to the calendar.selecteddates collection. ASP formats these cells differently, and I get the effect I wanted.

The problem: when the user clicks on a date, the collection is cleared and the newly selectected date is added to the (now empty) collection. I have been dealing with this by resetting the collection in the calendar.onselectionchanged event. So *every* time a user clicks a date, I have to add as many as 365 items to this collection.

This is definitely not pretty, and I am afraid that it will prove to be a drag on server resources. Is there a way to simply cancel the user's selection (but still know, programattically, which date s/he selected?) and avoid all of this? I'm sure many of you have done something similar -- any suggestions?

Thanks! -Brad
 
Try this:

put the following code in your dayrender sub

dates is a sortedlist. the for loop goes through all dates you have in your db and compares it to the day currently being rendered. if it matches you exit out of your loop. the dayrender sub is called everytime the page reloads, so everytime you click on a date...

Sub Calendar1_DayRender(sender As System.Object,e As DayRenderEventArgs)

dim otherdate as Date

Dim tc As TableCell
tc = New TableCell()


for each otherdate in dates.keys

'if rendered date equals date in db/sorted list key
If e.Day.Date = otherdate Then

e.Cell.BackColor = tc.BackColor.gold

' MUST EXIT LOOP IF A DATE MATCHES
exit for

end if

next otherdate

end sub


let me know if this helps...

J
 
Thanks for the pointer, J -- that makes good sense. -b
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top