linking the Calendar control to a database

coisyAnopsy

New Member
Here's the situation. We have an Access database with some meeting schedules.<BR><BR>I'd like to use ASP.NET's Calendar to display the meeting times and locations for a given day. In other words, if you view March 2002 on the Calendar, I'd like to be able to show the meetings and locations underneath each Date, where applicable. So if two meetings occur on March 18th, have their info display in the box for March 18th on the Calendar.<BR><BR>Is this possible, and if so, can anyone point me to some examples? If this can be done and I will be one happy guy.I have used vb.net for coding.I donot know which language you prefer.<BR><BR>Calendar.aspx.vb file:<BR><BR>Imports System.Drawing<BR>Imports System.Drawing.Imaging<BR>Imports System.Data<BR>Imports System.Data.SqlClient<BR>Imports System.Data.OleDb<BR>Imports System.Diagnostics.Debug<BR>Imports System.web<BR><BR>Public Class Calendar<BR> Inherits System.Web.UI.Page<BR> Protected WithEvents Label1 As System.Web.UI.WebControls.Label<BR> Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar<BR>#Region " Web Form Designer Generated Code "<BR><BR> 'This call is required by the Web Form Designer.<BR> <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<BR><BR> End Sub<BR><BR> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init<BR> 'CODEGEN: This method call is required by the Web Form Designer<BR> 'Do not modify it using the code editor.<BR> InitializeComponent()<BR> End Sub<BR><BR>#End Region<BR><BR> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> 'Put user code to initialize the page here<BR><BR> End Sub<BR><BR> Public Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender<BR> ' Dim Clicked_Date As Date = Calendar1.SelectedDate.ToShortDateString()<BR> Dim vacationStyle As New Style()<BR> Dim weekendStyle As New Style()<BR> 'Declare database objects<BR> Dim strConnect As String = "Provider=SQLOLEDB;data source=localhost;initial catalog=xxx;UID=sa;pwd=;"<BR> Dim objConnect As New OleDbConnection(strConnect)<BR> Dim objCommand As New OleDbCommand("Calendar1", objConnect)<BR> Dim objReader As OleDbDataReader<BR> Dim UserName As String = Request.Cookies("Name").Value<BR> objCommand.CommandType = CommandType.StoredProcedure<BR> Dim objParam As OleDbParameter<BR> objParam = objCommand.Parameters.Add("FName", OleDbType.Char, 20)<BR> objParam.Direction = ParameterDirection.Input<BR> objParam.Value = http://aspmessageboard.com/archive/index.php/UserName<BR> Try<BR> objCommand.Connection.Open()<BR> objReader = objCommand.ExecuteReader<BR> Catch myException As OleDbException<BR> Response.Write("Error retrieving data.")<BR> End Try<BR> While objReader.Read()<BR> Dim Info1 As String = objReader("UInfo").ToString()<BR> Dim Year1 As Integer = Year(objReader("UDate"))<BR> Dim Month1 As Integer = Month(objReader("Udate"))<BR> Dim Day1 As Integer = Day(objReader("Udate"))<BR> If e.Day.Date = New Date(Year1, Month1, Day1) Then<BR> Dim label1 As New Label()<BR> label1.Text = "<BR>" & Info1<BR> e.Cell.Controls.Add(label1)<BR> End If<BR> End While<BR> e.Cell.Controls.Add(New LiteralControl(ChrW(60) & "a href=EditCalendar.aspx?date=" & e.Day.Date & ChrW(62) & " C" & ChrW(60) & "/" & ChrW(62)))<BR> objReader.Close()<BR> objCommand.Connection.Close()<BR> If (e.Day.IsToday) Then<BR> e.Cell.BackColor = System.Drawing.Color.Red<BR> End If<BR> ' Display weekend dates in green boxes.<BR> If (e.Day.IsWeekend) Then<BR> weekendStyle.BackColor = System.Drawing.Color.Green<BR> e.Cell.ApplyStyle(weekendStyle)<BR> End If<BR> End Sub<BR><BR>End Class<BR><BR><BR>Calendar.aspx file:<BR><BR><%@ Page Language="vb" AutoEventWireup="false" Codebehind="Calendar.aspx.vb" Inherits="login.Calendar"%><BR><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><BR><HTML><BR> <HEAD><BR> <title></title><BR> <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR"><BR> <meta content="Visual Basic 7.0" name="CODE_LANGUAGE"><BR> <meta content="JavaScript" name="vs_defaultClientScript"><BR> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"><BR> </HEAD><BR> <body MS_POSITIONING="GridLayout"><BR> <form id="Form1" method="post" runat="server"><BR> <!--<asp:DataGrid id="DataGrid1" AutoGenerateColumns="true" runat="Server" />--><BR> <asp:calendar id="Calendar1" CellPadding="10" CellSpacing="10" Runat="server" Font-Name="Verdana;Arial" ShowGridLines="True" Font-Size="10px" TitleStyle-BackColor="Gainsboro" TitleStyle-Font-Size="12px" TitleStyle-Font-Bold="true" DayStyle-VerticalAlign="Top" DayStyle-Height="20px" DayStyle-Width="10%" SelectedDayStyle-BackColor="Navy" OtherMonthDayStyle-BackColor="#999999"></asp:calendar><BR> </form><BR> </body><BR></HTML><BR>.
 
Back
Top