calendar control : how to retrieve the "shown" month and year

T

tfsmag

i need to create a date range based on the current "shown" month on a
calendar control to query a database and populate a datagrid based on
that date range.

how can i retrieve the "shown" month and year from the calendar control
to create this range. Here is what i was thinking, all i need is the
"shown" month and year to complete.

-----------------------------------------------
Dim themonth as string = (need code to retreive "shown" month)
Dim theyear as string = (need code to retreive "shown" year)
Dim BeginRange as date
Dim EndRange as date
BeginRange = themonth & "/1/" & theyear
Dim daysinmonth As Integer = BeginRange.DaysInMonth(theyear, themonth)
EndRange = themonth & "/" & daysinmonth & "/" & theyear
 
K

Kim Quigley

Let me know if this code works:
Dim themonth As String = Me.Calendar1.VisibleDate.Month
Dim theyear As String = Me.Calendar1.VisibleDate.Year
 
T

tfsmag

i should also mention that i will need the variables to reflect the
"shown" date, so that means when it moves forward a month, beginrange
and endrange need to move forward a month.
 
T

tfsmag

visible date was not set, if i set the visible date to date.now it
doesn't change with the month. is there a way to make visibledate
change when you click forward or backward a month?
 
K

Kim Quigley

Now I'm confused about what you're asking. If you don't set VisibleDate
anywhere, then it defaults to the current month until the user changes it.
VisibleDate should always be the same as what you are actually seeing.

Maybe you are putting your code in the wrong spot. I tried checking
VisibleDate from the Page_Load, but it wasn't set. Try putting your code
inside the VisibleMonthChanged method. Of course, someone will actually have
to change the month for this event to fire. But if the month hasn't been
changed or set, then you'll know what the values of BeginRange and EndRange
should be (the current month)

Private Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.MonthChangedEventArgs) Handles
Calendar1.VisibleMonthChanged
Dim themonth As String = Me.Calendar1.VisibleDate.Month
Dim theyear As String = Me.Calendar1.VisibleDate.Year
Dim BeginRange As Date
Dim EndRange As Date
BeginRange = themonth & "/1/" & theyear
Dim daysinmonth As Integer = BeginRange.DaysInMonth(theyear, themonth)
EndRange = themonth & "/" & daysinmonth & "/" & theyear
End Sub
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top