Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 4th, 2008, 06:33 PM
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 Using month & year variable to get date in range

I have an "Event" table where I am going to be storing dates. I then have a calendar control and want to "select" or "highlight" the dates from my table that relate to the month chosen. I know how to do this with something like:

For Each tdate As Date In testDates
            Calendar1.SelectedDates.Add(tdate)
Next

My question is - how can I:

a) tie into the month changing event
b) grab the current month and year of the calendar control
c) use these to query the event table to only get events in the month and year passed to it?

THANKS!! - in the past, I never used "dates" but would store integers to store month, day and year - but would wind up writing too much custom code to work with dates where I think it would be easier to just store the date in the table.

Sincerely,
Rob

  #2 (permalink)  
Old July 4th, 2008, 08:39 PM
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

Ok, I figured out how to get the month and day - and have to use two different events to get them based upon if it's the first time the page loads or if selected month is changed...so, for the first time, I put the following in Page_Load and do a If Not page.ispostback--for the other I put it in the event if selectedmonthchanged.

 Dim month As Integer = Calendar1.VisibleDate.Year.ToString
 Dim year As Integer = Calendar1.VisibleDate.Month.ToString

Now - I can pass these as parameters to a SQL statment - but not sure how to work it to pull only those months in the month and year passed. This is probably, now, more of a TSQL question than ASP - but could sure use the help if someone knows.

Many Thanks,
Rob

  #3 (permalink)  
Old July 5th, 2008, 08:30 AM
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


 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pull Month & Year from Date(dd/mm/yyyy) istcomnet Classic ASP Basics 2 April 22nd, 2008 06:22 PM
Finding nday of evry month within date range arnabghosh Classic ASP Professional 0 December 6th, 2007 01:42 AM
find days per month in a date range rojer MySQL 1 June 5th, 2007 07:36 PM
Month and Year to Date on a Report Mitch Access 2 February 20th, 2007 10:23 AM
Month() Year() questions eon ASP.NET 1.0 and 1.1 Basics 1 October 4th, 2003 04:12 AM



All times are GMT -4. The time now is 11:26 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.