Multiple Calendar Control on one page



I have a page that has 12 calendars, one for each year and I have postback
events to record the change when the user click. The change is written to a
database and then the page refreshed with the dates selected as highlighted
in red.

This is an availability page with 12 calendars. The problem is that all the
calendars work, except #12 for december. When the postback events take place,
or when the page refreshes, the calendar for December goes blank. If I close
and open the page, then the calendar reflect the booked dates.

Any suggestions? Most code is below.


Imports System.Reflection
Imports System.Data.Odbc
Public Class propcal
Inherits System.Web.UI.Page
Public pass As Date
Public datinf(900) As Date
Public x As Integer
Public years As String
Public PID As String
Public listno As String

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents year1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar2 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar5 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar6 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar7 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar8 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar9 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar10 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar11 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar12 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar3 As System.Web.UI.WebControls.Calendar
Protected WithEvents Calendar4 As System.Web.UI.WebControls.Calendar

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim mo As String
Dim ye As String
mo = Month(Now())
ye = Year(Now())
PID = Request.QueryString("VAL1")
'Response.Write(years)
If Page.IsPostBack = True Then
years = year1.SelectedItem.Value
Else
years = ""
End If
If years <> "" Then
ye = Year(CDate(years + "-01-01"))
End If
If Page.IsPostBack = False Then
year1.Items.Clear()
year1.Items.Add(CStr(Year(Now())))
year1.Items.Add(CStr(Year(Now()) + 1))
year1.Items.Add(CStr(Year(Now()) + 2))
End If
If years = year1.Items(0).Value Then
year1.Items(0).Selected = True
End If
If years = year1.Items(1).Value Then
year1.Items(1).Selected = True
End If
If years = year1.Items(2).Value Then
year1.Items(2).Selected = True
End If
If Page.IsPostBack = False Then
year1.Items(0).Selected = True
End If
Calendar1.TodaysDate = CDate("1/" + ye)
If Calendar1.TodaysDate.DayOfWeek = 0 Or
Calendar1.TodaysDate.DayOfWeek = 6 Then
Calendar1.TodayDayStyle.BackColor =
Calendar1.WeekendDayStyle.BackColor
Else
Calendar1.TodayDayStyle.BackColor = Calendar1.DayStyle.BackColor
End If
Calendar2.TodaysDate = CDate("2/" + ye)
If Calendar2.TodaysDate.DayOfWeek = 0 Or
Calendar2.TodaysDate.DayOfWeek = 6 Then
Calendar2.TodayDayStyle.BackColor =
Calendar2.WeekendDayStyle.BackColor
Else
Calendar2.TodayDayStyle.BackColor = Calendar2.DayStyle.BackColor
End If
Calendar3.TodaysDate = CDate("3/" + ye)
If Calendar3.TodaysDate.DayOfWeek = 0 Or
Calendar3.TodaysDate.DayOfWeek = 6 Then
Calendar3.TodayDayStyle.BackColor =
Calendar3.WeekendDayStyle.BackColor
Else
Calendar3.TodayDayStyle.BackColor = Calendar3.DayStyle.BackColor
End If
Calendar4.TodaysDate = CDate("4/" + ye)
If Calendar4.TodaysDate.DayOfWeek = 0 Or
Calendar4.TodaysDate.DayOfWeek = 6 Then
Calendar4.TodayDayStyle.BackColor =
Calendar4.WeekendDayStyle.BackColor
Else
Calendar4.TodayDayStyle.BackColor = Calendar4.DayStyle.BackColor
End If
Calendar5.TodaysDate = CDate("5/" + ye)
If Calendar5.TodaysDate.DayOfWeek = 0 Or
Calendar5.TodaysDate.DayOfWeek = 6 Then
Calendar5.TodayDayStyle.BackColor =
Calendar5.WeekendDayStyle.BackColor
Else
Calendar5.TodayDayStyle.BackColor = Calendar5.DayStyle.BackColor
End If
Calendar6.TodaysDate = CDate("6/" + ye)
If Calendar6.TodaysDate.DayOfWeek = 0 Or
Calendar6.TodaysDate.DayOfWeek = 6 Then
Calendar6.TodayDayStyle.BackColor =
Calendar6.WeekendDayStyle.BackColor
Else
Calendar6.TodayDayStyle.BackColor = Calendar6.DayStyle.BackColor
End If
Calendar7.TodaysDate = CDate("7/" + ye)
If Calendar7.TodaysDate.DayOfWeek = 0 Or
Calendar7.TodaysDate.DayOfWeek = 6 Then
Calendar7.TodayDayStyle.BackColor =
Calendar7.WeekendDayStyle.BackColor
Else
Calendar7.TodayDayStyle.BackColor = Calendar7.DayStyle.BackColor
End If
Calendar8.TodaysDate = CDate("8/" + ye)
If Calendar8.TodaysDate.DayOfWeek = 0 Or
Calendar8.TodaysDate.DayOfWeek = 6 Then
Calendar8.TodayDayStyle.BackColor =
Calendar8.WeekendDayStyle.BackColor
Else
Calendar8.TodayDayStyle.BackColor = Calendar8.DayStyle.BackColor
End If
Calendar9.TodaysDate = CDate("9/" + ye)
If Calendar9.TodaysDate.DayOfWeek = 0 Or
Calendar9.TodaysDate.DayOfWeek = 6 Then
Calendar9.TodayDayStyle.BackColor =
Calendar9.WeekendDayStyle.BackColor
Else
Calendar9.TodayDayStyle.BackColor = Calendar9.DayStyle.BackColor
End If
Calendar10.TodaysDate = CDate("10/" + ye)
If Calendar10.TodaysDate.DayOfWeek = 0 Or
Calendar10.TodaysDate.DayOfWeek = 6 Then
Calendar10.TodayDayStyle.BackColor =
Calendar10.WeekendDayStyle.BackColor
Else
Calendar10.TodayDayStyle.BackColor = Calendar10.DayStyle.BackColor
End If
Calendar11.TodaysDate = CDate("11/" + ye)
If Calendar11.TodaysDate.DayOfWeek = 0 Or
Calendar11.TodaysDate.DayOfWeek = 6 Then
Calendar11.TodayDayStyle.BackColor =
Calendar11.WeekendDayStyle.BackColor
Else
Calendar11.TodayDayStyle.BackColor = Calendar11.DayStyle.BackColor
End If
Calendar12.TodaysDate = CDate("12/" + ye)
If Calendar12.TodaysDate.DayOfWeek = 0 Or
Calendar12.TodaysDate.DayOfWeek = 6 Then
Calendar12.TodayDayStyle.BackColor =
Calendar12.WeekendDayStyle.BackColor
Else
Calendar12.TodayDayStyle.BackColor = Calendar12.DayStyle.BackColor
End If
getinfo()
End Sub
Public Sub getinfo()
Dim MyConString As String = 'removed for security'
'Connection
Dim MyConnection As New OdbcConnection(MyConString)
MyConnection.Open()
Dim MyCommand As New OdbcCommand("SELECT * from usr_prop_cal where
PID='" + PID + "'", MyConnection)
If years <> "" Then
MyCommand.CommandText = "SELECT * from usr_prop_cal where PID='"
+ PID + "' and dat between '" + years + "-01-01' and '" + years + "-12-01' "
End If
Dim myReader As OdbcDataReader =
MyCommand.ExecuteReader(Data.CommandBehavior.CloseConnection)
Dim dat As Date
Dim mo As Integer
Dim ye As Integer

x = 0
While myReader.Read
dat = myReader.GetDateTime(2)
datinf(x) = myReader.GetDateTime(2)
mo = Month(dat)
ye = Year(dat)
x = x + 1
End While
myReader.Close()
MyCommand.CommandText = "Select listno from usr_prop where PID = '"
+ PID + "'"
MyConnection.Open()
myReader =
MyCommand.ExecuteReader(Data.CommandBehavior.CloseConnection)
While myReader.Read
listno = CStr(myReader.GetInt32(0))
End While
myReader.Close()
Label1.Text = "Property list number: " + listno
myReader = Nothing
MyCommand.Dispose()
MyConnection.Dispose()
End Sub
Private Sub postit(ByVal datpas As Date, ByVal weekpas As Integer)
'Response.Write(datpas)
'Response.Write(weekpas)
Dim MyConString As String = 'removed for security'
Dim mycon2 As New OdbcConnection(MyConString)
mycon2.Open()
Dim MyCommand As New OdbcCommand("SELECT * from usr_mm where (sent
is null OR sent='') and (countmeout is null or countmeout='')", mycon2)
Dim mycmd As New OdbcCommand("Select ct(email) as ct from usr_mm",
mycon2)
mycmd.CommandText = "Select Max(RID) as rid from usr_prop_cal"
Dim myReader As OdbcDataReader =
mycmd.ExecuteReader(Data.CommandBehavior.CloseConnection)
Dim rid As Integer
While myReader.Read
rid = myReader.GetInt32(0)
End While
rid = rid + 1
myReader.Close()
Dim dat As String

If weekpas = 1 Then
dat = CStr(Year(datpas)) + "-" + CStr(Month(datpas)) + "-" +
CStr(Day(datpas))

mycmd.CommandText = "Select count(RID) as ct from usr_prop_cal
where dat = '" + dat + " 00:00:00' and PID = '" + PID + "'"
'Response.Write(mycmd.CommandText)
mycon2.Open()
myReader =
mycmd.ExecuteReader(Data.CommandBehavior.CloseConnection)
Dim ct As Integer
While myReader.Read
ct = myReader.GetInt32(0)
End While
myReader.Close()
mycon2.Open()
If ct > 0 Then
mycmd.CommandText = "Delete from usr_prop_cal where dat = '"
+ dat + " 00:00:00' and PID = '" + PID + "'"
mycmd.ExecuteNonQuery()
Else
mycmd.CommandText = "Insert into usr_prop_cal (PID, RID,
dat) VALUES ('" + PID + "','" + CStr(rid) + "','" + dat + "')"
mycmd.ExecuteNonQuery()
End If
'Response.Write(mycmd.CommandText)
End If
If weekpas = 7 Then
Dim ct2 As Integer
datpas = DateAdd(DateInterval.Day, CDbl(-1), datpas)
For ct2 = 0 To weekpas - 1
datpas = DateAdd(DateInterval.Day, CDbl(1), datpas)
dat = CStr(Year(datpas)) + "-" + CStr(Month(datpas)) + "-" +
CStr(Day(datpas))

mycmd.CommandText = "Select count(RID) as ct from
usr_prop_cal where dat = '" + dat + " 00:00:00' and PID = '" + PID + "'"
If mycon2.State <> Data.ConnectionState.Open Then
mycon2.Open()
End If
myReader =
mycmd.ExecuteReader(Data.CommandBehavior.CloseConnection)
Dim ct As Integer
While myReader.Read
ct = myReader.GetInt32(0)
End While
myReader.Close()
mycon2.Open()
If ct > 0 Then
mycmd.CommandText = "Delete from usr_prop_cal where dat
= '" + dat + " 00:00:00' and PID = '" + PID + "'"
mycmd.ExecuteNonQuery()
Else
mycmd.CommandText = "Insert into usr_prop_cal (PID, RID,
dat) VALUES ('" + PID + "','" + CStr(rid) + "','" + dat + "')"
mycmd.ExecuteNonQuery()
End If
rid = rid + 1

Next ct2

End If
mycon2.Close()
mycmd.Dispose()
mycon2.Dispose()
getinfo()
End Sub
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar2_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar2.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar3_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar3.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar4_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar4.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar5_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar5.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar6_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar6.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar7_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar7.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar8_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar8.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar9_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar9.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar10_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar10.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar11_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar11.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar12_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar12.DayRender
Dim c As Integer
For c = 0 To x - 1
If e.Day.Date.Month = Month(datinf(c)) Then
If e.Day.Date.Day = Day(datinf(c)) = True Then
e.Cell.BackColor = System.Drawing.Color.Red
End If
End If
Next c
End Sub
Private Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar1.SelectionChanged
postit(Calendar1.SelectedDate, Calendar1.SelectedDates.Count)
Calendar1.SelectedDate = Nothing
End Sub
Private Sub Calendar2_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar2.SelectionChanged
postit(Calendar2.SelectedDate, Calendar2.SelectedDates.Count)
Calendar2.SelectedDate = Nothing
End Sub
Private Sub Calendar3_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar3.SelectionChanged
postit(Calendar3.SelectedDate, Calendar3.SelectedDates.Count)
Calendar3.SelectedDate = Nothing
End Sub
Private Sub Calendar4_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar4.SelectionChanged
postit(Calendar4.SelectedDate, Calendar4.SelectedDates.Count)
Calendar4.SelectedDate = Nothing
End Sub
Private Sub Calendar5_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar5.SelectionChanged
postit(Calendar5.SelectedDate, Calendar5.SelectedDates.Count)
Calendar5.SelectedDate = Nothing
End Sub
Private Sub Calendar6_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar6.SelectionChanged
postit(Calendar6.SelectedDate, Calendar6.SelectedDates.Count)
Calendar6.SelectedDate = Nothing
End Sub
Private Sub Calendar7_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar7.SelectionChanged
postit(Calendar7.SelectedDate, Calendar7.SelectedDates.Count)
Calendar7.SelectedDate = Nothing
End Sub
Private Sub Calendar8_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar8.SelectionChanged
postit(Calendar8.SelectedDate, Calendar8.SelectedDates.Count)
Calendar8.SelectedDate = Nothing
End Sub
Private Sub Calendar9_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar9.SelectionChanged
postit(Calendar9.SelectedDate, Calendar9.SelectedDates.Count)
Calendar9.SelectedDate = Nothing
End Sub
Private Sub Calendar10_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar10.SelectionChanged
postit(Calendar10.SelectedDate, Calendar10.SelectedDates.Count)
Calendar10.SelectedDate = Nothing
End Sub
Private Sub Calendar11_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar11.SelectionChanged
postit(Calendar11.SelectedDate, Calendar11.SelectedDates.Count)
Calendar11.SelectedDate = Nothing
End Sub
Private Sub Calendar12_SelectionChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Calendar12.SelectionChanged
postit(Calendar12.SelectedDate, Calendar12.SelectedDates.Count)
Calendar12.SelectedDate = Nothing
End Sub
End Class



.



Relevant Pages

  • Calendar Control issue.
    ... Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar ... Private Sub Page_Init(ByVal sender As System.Object, ... Dim mo As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Strange FileWatch problem
    ... Private Sub Form1_Load(ByVal sender As System.Object, ... Dim Form2 As New Form2 ...
    (microsoft.public.dotnet.general)
  • Re: Strange FileWatch problem
    ... Private Sub Form1_Load(ByVal sender As System.Object, ... Dim Form2 As New Form2 ...
    (microsoft.public.dotnet.general)
  • Strange FileWatch problem
    ... Private Sub Form1_Load(ByVal sender As System.Object, ... Dim Form2 As New Form2 ...
    (microsoft.public.dotnet.general)
  • A VB6 program to generate CONSTants for a user defined gradient
    ... EndProperty ... It may be used for amy moral purpose. ... Dim mGreen1 As Long ... Private Sub ColorDisplay_MouseDown(Button As Integer, Shift As Integer, _ ...
    (comp.lang.basic.visual.misc)