I'm working on a project that queries a SQL database. My current phase deals with selecing dates from a calendar and passing those dates to a report page which used the two dates from the previous page in a sql string. They pick two dates and click submit to pass the querystrings to a second page where the datagrid is located.
I'm using VB in asp.net. To make date selection easier, I'm trying to use two calendars. Calendar1 is used to select the report "start" date. Calendar2 is used to select the report "end" date. The dates can be as far apart as the user desires including the start and end date selections being the same day. The only restrictions I am trying to limit is a) the user cannot pick a date in the future, b) the user cannot pick a start date which is greater than the end date, c) likewise, the user can't choose an end date first which is less than the start date.
For instance, if I want to report on the period between Tuesday, July 5th 2005 and Thursday, July 14th 2005, I select those respective dates accordingly.
I've tried so many different things I don't know where to start. But, here's what it boils down to. I always set the selecteddate property to date.now. At all times, I need to compare dates. However, there are conditions when Calendar1 ignores Calendar2 and vice versa. I'm trying to prevent the user from picking illogical dates. Currently, my page works if the user picks the start date and end date correctly right off the bat. However, I've had cases where they change their mind after picking a start date and end date and then they go BACK to calendar1 and change the date without clicking the clear button to reset the calendars.
I'm quite positive it's my error logic that I'm using. I've tried checking/comparing date values within each calendar change function.
I've tried searching the internet for examples of this situation.
My example code here is going to be quite a mess as I've been making multiple changes and it's VERY buggy at the moment, but you'll get the idea.
Sub Selection_Change1(ByVal sender As Object, ByVal e As EventArgs)
If Calendar1.SelectedDate.ToS
hortDateSt
ring < Calendar2.SelectedDate.ToS
hortDateSt
ring Then
Label1.ForeColor = Drawing.Color.Black
Label1.Text = Calendar1.SelectedDate.ToS
hortDateSt
ring
Label2.Text = Calendar2.SelectedDate.ToS
hortDateSt
ring
ElseIf Calendar1.SelectedDate.ToS
hortDateSt
ring > Calendar2.SelectedDate.ToS
hortDateSt
ring Then
Label1.ForeColor = Drawing.Color.Red
Label1.Text = "Start date is greater than end date. Please try again. Calendar1 " & Calendar1.SelectedDate.ToS
hortDateSt
ring
Label2.Text = Calendar2.SelectedDate.ToS
hortDateSt
ring
End If
End Sub 'Selection_Change for Calendar1
Sub Selection_Change2(ByVal sender As Object, ByVal e As EventArgs)
If Calendar2.SelectedDate.ToS
hortDateSt
ring > Calendar1.SelectedDate.ToS
hortDateSt
ring Then
Label2.ForeColor = Drawing.Color.Black
Label2.Text = Calendar2.SelectedDate
ElseIf Calendar2.SelectedDate.ToS
hortDateSt
ring < Calendar1.SelectedDate.ToS
hortDateSt
ring Then
Label2.ForeColor = Drawing.Color.Red
Label2.Text = "End date is less than start date. Please try again. Calendar2 " & Calendar2.SelectedDate.ToS
hortTimeSt
ring
End If
End Sub 'Selection_Change for Calendar2
So, my question is, how do I accomplish what I want to do? I'm still a greenhorn when it comes to a lot of vb programming, so please go easy on this old man.
Thanks
Ted
Start Free Trial