View Single Post
  #3 (permalink)  
Old July 5th, 2008, 08:30 AM
rsearing rsearing is offline
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

I can't tell you how many times a good nights sleep has helped me to solve a problem. Below is my function and SQL:

Protected Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles Calendar1.VisibleMonthChanged
        Dim month As Integer = Calendar1.VisibleDate.Month.ToString
        Dim year As Integer = Calendar1.VisibleDate.Year.ToString

        Dim myEventDates As New List(Of Date)
        Dim myEvents As New CAGEventList
        myEvents = CAGEventDB.GetEventDates(month, year)
        If Not myEvents Is Nothing Then
            For Each myCAGEVent As CAGEvent In myEvents
                myEventDates.Add(myCAGEVent.eventDate)
            Next

            For Each myDate As Date In myEventDates
                Calendar1.SelectedDates.Add(myDate)
            Next
        End If
    End Sub

NOTE: I have something similar in Page_Load to capture the calendar when page first loads. Since the calendar will always show current month I simply change my variables to:
Dim month As Integer = Date.Today.Month
Dim year As Integer = Date.Today.Year

Then, here is my SQL statement:


ALTER PROCEDURE dbo.sprocCAGEventGetEventListByMonthAndYear

    @myMonth integer,
    @myYear integer
AS

BEGIN
    SET NOCOUNT ON
    SELECT
        eventID,
        eventTitle,
        eventDescription,
        eventDate,
        eventLocation

    FROM
        CAGEvent
    WHERE
        MONTH(eventDate)=@myMonth AND YEAR(eventDate)=@myYear

    END