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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display or select multiple dates in a calendar 2

Status
Not open for further replies.

NoCoolHandle

Programmer
Apr 10, 2003
2,321
US
I am looking for a way to display muiltple dates inside a calendar control.

E.G. 9/5/2007; 9/12/2007; 9/23/2007-9/25/2007

I read somewhere that you could extend the basic calendar control to do this, but haven't been able to find the clues needed to get it working..

Any help appreciated.

Rob
 
I found this on the web... you could try it:
How to display multiple dates selected in Calendar Control?

Set the SelectionMode property of Calendar Control to DayWeek/ DayWeekMonth.
Code for the OnSelectionChanged as follows:

VB.NET

Dim day As DateTime
Dim strval As String
For Each day In Calendar1.SelectedDates
strval += (day.Date.ToShortDateString() & "<br>")
Next
Response.Write(strval)


C#

string strval="" ;
foreach (DateTime day in Calendar1.SelectedDates)
{
strval += (day.Date.ToShortDateString() + "<br>");
}
Response.Write(strval);
}


Otherwise you may have to buy something like this:

Senior Software Developer
 
Mark, (I think I managed to write the original question wrong)

the goal would to be able to query a database for the dates that events are scheduled and then format the cell with different background color to indicate that the date has an event.

That way when a user clicks on a date that has an event, the page could go directly to the events information.

.. so no I guess I don't want to select more than one day, just display the fact that more than a single day might have an event for it...

(hopefully that makes more sense)

Rob
 
In that case you can just use the DayRender event and set the style do something else (ideally by using CSS and setting the CssClass for the current item).


------------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
 
Again... How does this not help??? I'm confused.

Code:
        Calendar1.SelectedDates.Add(Now.Date)
        Calendar1.SelectedDates.Add(Now.AddDays(2).Date)

Senior Software Developer
 
I couldn't help it... I had to play with that one.

Code:
    Protected Sub Calendar1_DayRender(ByVal sender As Object, _
        ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
        If e.Day.Date = Now.Date.AddDays(5) Then
            e.Cell.BackColor = Drawing.Color.Crimson
        End If
    End Sub
And then you just use the Style property for the css.

pretty cool.

Senior Software Developer
 
I haven't had a chance to try this yet, but it looks just like I need. Thanks to both of you!!!

Rob
 
[wiggle][wiggle][2thumbsup] WOW!!!! [2thumbsup][wiggle][wiggle]

Thanks guys.. Both for the css idea, the property assignment and also the adding selected items.

I am certain that this has just changed a good number of future projects for me. What a great control!

(and a great forum-which is dependent on your help)

THANKS AGAIN

Rob
PS You deserve more than one star for this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top