Hello everyone and thanks for your help in advance. I am working on a scheduling application for a physician. The work in progress can be viewed at http://www.kidsmedicalcare.com/schedule2.aspx
. Where I am running into problems is when a date is clicked on the calendar, the appointments for the day should be loaded. What seems to be happening is that when a date with appointments is clicked, the appointments appear correctly, but then do not disappear properly when another date is clicked. Here are some code snippets:
The appointment grid is built by a sub routine called LoadTable(). Basically, it adds rows and cells to a table with hyperlinks corresponding to the date and time of the appointment. The current date with a starting time of 8:00 am is passed to the sub. The routine assigns an ID value to each hyperlink corresponding with the date and time, to be referenced by the GetAppointments() routine later.
Public Sub LoadTable(ByVal StartTime As DateTime)
Dim EndTime As DateTime = StartTime.ToShortDateString & " 5:00:00 pm"
ltlDate.Text = "Appointments for: <br>" & StartTime.ToShortDateString & " " & StartTime.ToShortTimeString
Dim ProviderCount As Integer
Do While StartTime < EndTime
StartTime = StartTime.AddMinutes(10)
'Add Label Column
Dim TimeLabel As New TableCell
TimeLabel.Text = StartTime.ToShortTimeString
TimeLabel.Text = StartTime.ToString
'Add Time Row
Dim TimeRow As New TableRow
'Add Provider Cells
For ProviderCount = 1 To 3
Dim AppointmentLink As New HyperLink
AppointmentLink.NavigateUrl = "appointment.aspx?Time=" & StartTime & "&Provider=" & ProviderCount
AppointmentLink.Text = StartTime.ToShortTimeString
AppointmentLink.NavigateUrl = "AppointmentDetails.aspx?ApptTime=" & StartTime.ToString
AppointmentLink.Target = "AppointmentDetails.aspx?AppTime=" & StartTime.ToString
AppointmentLink.ID = "Provider" & ProviderCount & "_" & StartTime.ToShortDateString & " " & StartTime.ToShortTimeString
AppointmentLink.ID = Replace(AppointmentLink.ID, ":", "_")
AppointmentLink.ID = Replace(AppointmentLink.ID, " ", "_")
Dim ProviderCell As New TableCell
Next, appointments already booked for the day are queried from a database and returned as a dataview. A routine called GetAppointments() does this. Once the data is retrieved, each appointment record is looped through, looking for a corresponding ID value based on the date and time of the appointment. If one is located, the hyperlink is reformatted with the name of the patients and a different URL to navigate to:
For Each Appointment In Appointments
If Not IsDBNull(Appointment("AppointmentTime")) Then
Literal1.Text = Literal1.Text & Appointment("AppointmentTime") & "<br>"
Dim ApptTime As DateTime = Appointment("AppointmentTime")
'Dim strAppointmentTime As String = ApptTime.ToShortTimeString
Dim strAppointmentTime As String = ApptTime.ToShortDateString & " " & ApptTime.ToShortTimeString
strAppointmentTime = Replace(strAppointmentTime, ":", "_")
strAppointmentTime = Replace(strAppointmentTime, " ", "_")
strAppointmentTime = "Provider1_" & strAppointmentTime
Dim lnkAppointmentLink As HyperLink = FindControl(strAppointmentTime)
If Not (lnkAppointmentLink Is Nothing) Then
If Not IsDBNull(Appointment("LastName")) Then
lnkAppointmentLink.Text = Appointment("LastName")
If Not IsDBNull(Appointment("FirstName")) Then
lnkAppointmentLink.Text = lnkAppointmentLink.Text & ", " & Appointment("FirstName") & "<br>"
If Not IsDBNull(Appointment("AppointmentType")) Then
lnkAppointmentLink.Text = lnkAppointmentLink.Text & Appointment("AppointmentType")
If Not IsDBNull(Appointment("ID")) Then
lnkAppointmentLink.NavigateUrl = "AppointmentDetails.aspx?ID=" & Appointment("ID")
lnkAppointmentLink.Target = "AppointmentDetails.aspx?ID=" & Appointment("ID")
Literal2.Text = Literal2.Text & (Appointment("AppointmentTime")) & "<br>"
Literal3.Text = Literal3.Text & strAppointmentTime & "<br>"
When a calendar date is clicked, it is handled with the following routine:
Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
'Literal1.Text = Calendar1.SelectedDate.ToShortDateString
StartTime = Calendar1.SelectedDate.ToShortDateString & " 8:00:00 am"
As I mentioned, I simply cannot figure out why the appointments from the previous day clicked do not clear since the table is dynamically rebuilt each time a new date is clicked. I have also palced some diagnostic data at the bottom of the page including all of the appointments in the databse and a listing of the days appointements along with the correspodnign controls the GetAppointments() routine should be trying to find. As I said earlier, I am completely stumped on this one. Any help on this would be greatly appreciated. Thanks.