W
Winshent
I am still learning ASP.net and am having a problem with rendering a
calendar control.
I initially had the control on the same page as the button which
triggered it to make it visible. Now i have dumped its own page so it
pops up through javascript. The calendar is now not being rendered.
The calender is being rendered so that all days with existing records
are disabled.
Any ideas? Here is the code from the aspx and aspx.vb files
Thanks
Vincent
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="frmCalendar.aspx.vb" Inherits="SPC.frmCalendar"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Calendar</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:calendar id="myCalendar" style="Z-INDEX: 141; LEFT: 8px;
POSITION: absolute; TOP: 8px" runat="server"
CellSpacing="1" Height="120px" Width="200px" Font-Size="X-Small"
Font-Names="Verdana" BorderColor="Blue"
BorderStyle="Inset">
<TodayDayStyle BackColor="#FFC0C0"></TodayDayStyle>
<DayStyle Font-Size="XX-Small" BorderWidth="1px"
BorderStyle="None" BackColor="White"></DayStyle>
<NextPrevStyle ForeColor="RoyalBlue"
BackColor="White"></NextPrevStyle>
<DayHeaderStyle Font-Size="XX-Small" Font-Names="Verdana"
BorderWidth="1px" ForeColor="White" BorderColor="Black"
BackColor="RoyalBlue"></DayHeaderStyle>
<SelectedDayStyle BorderColor="Black"
BackColor="RoyalBlue"></SelectedDayStyle>
<TitleStyle Font-Size="XX-Small" ForeColor="RoyalBlue"
BackColor="White"></TitleStyle>
<OtherMonthDayStyle Font-Size="XX-Small" Font-Names="Verdana"
Font-Strikeout="True" BackColor="Silver"></OtherMonthDayStyle>
</asp:calendar></form>
</body>
</HTML>
===========================================================================
Imports System.Web.ui
Public Class frmCalendar
Inherits System.Web.UI.Page
Private dsGroupDates As New DataSet
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Protected WithEvents myDataAdapter As
System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SelectGroupedDatesCmd As
System.Data.SqlClient.SqlCommand
Protected WithEvents myConnection As
System.Data.SqlClient.SqlConnection
Protected WithEvents myCalendar As
System.Web.UI.WebControls.Calendar
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
InitializeStuff()
myDataAdapter.Fill(dsGroupDates, "Results")
End Sub
Public Sub OpenConn()
myConnection = New
System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString"))
myConnection.Open()
End Sub
Public Sub CloseConn()
myConnection.Close()
End Sub
Private Sub InitializeStuff()
myDataAdapter = New System.Data.SqlClient.SqlDataAdapter
OpenConn()
SelectGroupedDatesCmd = New System.Data.SqlClient.SqlCommand
myDataAdapter.SelectCommand = SelectGroupedDatesCmd
SelectGroupedDatesCmd.CommandText = "SELECT LogDate FROM
tblResults GROUP BY LogDate ORDER BY LogDate"
SelectGroupedDatesCmd.Connection = myConnection
CloseConn()
End Sub
Private Sub Calendar_DayRender(ByVal sender As System.Object, ByVal
e As System.Web.UI.WebControls.DayRenderEventArgs)
Dim DateExists As Date
Dim i As Integer
For i = 0 To GetExistingDates.Count - 1
DateExists = GetExistingDates(i)("LogDate")
If (e.Day.Date = DateExists) Then
e.Day.IsSelectable = False
End If
Next
End Sub
Private Function GetExistingDates() As DataRowCollection
'Collection
myDataAdapter.SelectCommand = SelectGroupedDatesCmd
Dim RowsColl As DataRowCollection
Dim dView As DataView
RowsColl = dsGroupDates.Tables("Results").Rows
Return RowsColl
'dView = dsGroupDates.Tables("Results").DefaultView
End Function
End Class
calendar control.
I initially had the control on the same page as the button which
triggered it to make it visible. Now i have dumped its own page so it
pops up through javascript. The calendar is now not being rendered.
The calender is being rendered so that all days with existing records
are disabled.
Any ideas? Here is the code from the aspx and aspx.vb files
Thanks
Vincent
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="frmCalendar.aspx.vb" Inherits="SPC.frmCalendar"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Calendar</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:calendar id="myCalendar" style="Z-INDEX: 141; LEFT: 8px;
POSITION: absolute; TOP: 8px" runat="server"
CellSpacing="1" Height="120px" Width="200px" Font-Size="X-Small"
Font-Names="Verdana" BorderColor="Blue"
BorderStyle="Inset">
<TodayDayStyle BackColor="#FFC0C0"></TodayDayStyle>
<DayStyle Font-Size="XX-Small" BorderWidth="1px"
BorderStyle="None" BackColor="White"></DayStyle>
<NextPrevStyle ForeColor="RoyalBlue"
BackColor="White"></NextPrevStyle>
<DayHeaderStyle Font-Size="XX-Small" Font-Names="Verdana"
BorderWidth="1px" ForeColor="White" BorderColor="Black"
BackColor="RoyalBlue"></DayHeaderStyle>
<SelectedDayStyle BorderColor="Black"
BackColor="RoyalBlue"></SelectedDayStyle>
<TitleStyle Font-Size="XX-Small" ForeColor="RoyalBlue"
BackColor="White"></TitleStyle>
<OtherMonthDayStyle Font-Size="XX-Small" Font-Names="Verdana"
Font-Strikeout="True" BackColor="Silver"></OtherMonthDayStyle>
</asp:calendar></form>
</body>
</HTML>
===========================================================================
Imports System.Web.ui
Public Class frmCalendar
Inherits System.Web.UI.Page
Private dsGroupDates As New DataSet
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Protected WithEvents myDataAdapter As
System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SelectGroupedDatesCmd As
System.Data.SqlClient.SqlCommand
Protected WithEvents myConnection As
System.Data.SqlClient.SqlConnection
Protected WithEvents myCalendar As
System.Web.UI.WebControls.Calendar
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
InitializeStuff()
myDataAdapter.Fill(dsGroupDates, "Results")
End Sub
Public Sub OpenConn()
myConnection = New
System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString"))
myConnection.Open()
End Sub
Public Sub CloseConn()
myConnection.Close()
End Sub
Private Sub InitializeStuff()
myDataAdapter = New System.Data.SqlClient.SqlDataAdapter
OpenConn()
SelectGroupedDatesCmd = New System.Data.SqlClient.SqlCommand
myDataAdapter.SelectCommand = SelectGroupedDatesCmd
SelectGroupedDatesCmd.CommandText = "SELECT LogDate FROM
tblResults GROUP BY LogDate ORDER BY LogDate"
SelectGroupedDatesCmd.Connection = myConnection
CloseConn()
End Sub
Private Sub Calendar_DayRender(ByVal sender As System.Object, ByVal
e As System.Web.UI.WebControls.DayRenderEventArgs)
Dim DateExists As Date
Dim i As Integer
For i = 0 To GetExistingDates.Count - 1
DateExists = GetExistingDates(i)("LogDate")
If (e.Day.Date = DateExists) Then
e.Day.IsSelectable = False
End If
Next
End Sub
Private Function GetExistingDates() As DataRowCollection
'Collection
myDataAdapter.SelectCommand = SelectGroupedDatesCmd
Dim RowsColl As DataRowCollection
Dim dView As DataView
RowsColl = dsGroupDates.Tables("Results").Rows
Return RowsColl
'dView = dsGroupDates.Tables("Results").DefaultView
End Function
End Class