<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link rel="stylesheet" href="../css/mediaboxAdvBlack21.css" type="text/css" media="screen" />
<script src="../js/mootools.js" type="text/javascript"></script>
<script src="../js/mediaboxAdv-1.3.4.js" type="text/javascript"></script>
<title>Calendar</title>
</head>
<body>
<script type="text/javascript" src="../js/wz_tooltip.js"></script>
<script type="text/javascript" src="../js/tip_balloon.js"></script>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White"
BorderColor="Black" BorderWidth="1px" Font-Names="Segoe UI" Font-Size="9pt"
ForeColor="Black" Height="180px" NextPrevFormat="FullMonth" Width="260px"
SelectionMode="None" BorderStyle="Solid"
Caption="Calendar of Events" CaptionAlign="Top" ToolTip=" ">
<SelectedDayStyle BackColor="White" ForeColor="White" />
<SelectorStyle Font-Bold="False" />
<TodayDayStyle BackColor="White" Font-Bold="True"
Font-Names="Segoe UI" Font-Size="14px" />
<OtherMonthDayStyle ForeColor="#999999" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#F9F9D2"
VerticalAlign="Bottom" />
<DayHeaderStyle Font-Bold="True" Font-Size="8pt" BackColor="#F9F9D2"
BorderStyle="Solid" BorderWidth="0px" />
<TitleStyle BackColor="#931D1D" BorderColor="Black" BorderWidth="1px"
Font-Bold="True" Font-Size="13pt" ForeColor="White"
BorderStyle="Ridge" />
</asp:Calendar>
</div>
</form>
</body>
</html>
Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Protected dsEvents As DataSet
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Calendar1.VisibleDate = DateTime.Today
FillDataset()
End If
End Sub
Protected Sub FillDataset()
Dim firstDate As New DateTime(Calendar1.VisibleDate.Year, Calendar1.VisibleDate.Month, 1)
Dim lastDate As DateTime = GetFirstDayOfNextMonth()
dsEvents = GetCurrentMonthData(firstDate, lastDate)
End Sub
Protected Function GetFirstDayOfNextMonth() As DateTime
Dim monthNumber, yearNumber As Integer
If Calendar1.VisibleDate.Month = 12 Then
monthNumber = 1
yearNumber = Calendar1.VisibleDate.Year + 1
Else
monthNumber = Calendar1.VisibleDate.Month + 1
yearNumber = Calendar1.VisibleDate.Year
End If
Dim lastDate As New DateTime(yearNumber, monthNumber, 1)
Return lastDate
End Function
Protected Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) _
Handles Calendar1.VisibleMonthChanged
FillDataset()
End Sub
Function GetCurrentMonthData(ByVal firstDate As DateTime, ByVal lastDate As DateTime) As DataSet
Dim sConnectionString, sSQL As String
'SQL Connection String
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/_database/CalendarDb.mdb") & ";User Id=admin;Password=;"
Dim objConnection As New OleDbConnection(sConnectionString)
'SQL parameters
sSQL = "SELECT * FROM tblEvents WHERE eventDate >= #" & firstDate & "# And eventDate < #" & lastDate & "#"
Dim Table As New DataSet
Dim Adpt As New OleDbDataAdapter(sSQL, objConnection)
Table.Clear()
Try
Adpt.Fill(Table)
Catch
End Try
' return the recordset as an array
Return Table
End Function
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
Dim nextDate As DateTime
' Checks to see if there are any dates that need to be returned
If Not dsEvents Is Nothing Then
' if there is, then draw them
For Each dr As DataRow In dsEvents.Tables(0).Rows ' this array will be full of your db data
nextDate = CType(dr("eventDate"), DateTime)
If nextDate = e.Day.Date Then
'e.Cell.BackColor = System.Drawing.Color.Pink ' changes the background color
e.Day.IsSelectable = True ' makes the date selectable
e.Cell.Font.Bold = True
e.Cell.Controls.Clear()
Dim iLink As New HyperLink() ' Create a hyperlink of the date
iLink.Text = e.Day.Date.Day '& "<br>" & dr(2) ' sets the date as a link
iLink.ForeColor = Drawing.ColorTranslator.FromHtml("#931D1D") ' give it a cool color
iLink.Font.Underline = True ' underline it
' Here is where we create a nice ToolTip when the mouseOver event fires
iLink.Attributes.Add("onmouseover", "Tip('" & dr(2) & "', BALLOON, true, ABOVE, true, OFFSETX, -20)")
iLink.ToolTip = dr(2)
' Lets create the link to fire the Lightbox
iLink.NavigateUrl = Server.UrlPathEncode("javascript:this.onclick(Mediabox.open('#mb_inline" & dr(0) & "', '" & dr(2) & "', '360 180'));") ' the URL
e.Cell.Controls.Add(iLink) 'Add the link
buildDivTags(dr(0), dr(2), dr(3), dr(4))
End If
Next
End If
End Sub
' We need to create <Div> tags to control the output of the Lightbox contents
Private Sub buildDivTags(ByRef id As String, ByRef title As String, ByRef data As String, ByRef link As String)
Response.Write(vbCrLf & "<div id='mb_inline" & id & "' style='display: none;'>" & vbCrLf)
Response.Write("<span style='color: #fff; text-align: center;'><A href='" & link & "' target='_blank' id='mbTitleLink'>" & title & "</a><br/><br/>" & vbCrLf)
Response.Write(data & "<br/><br/>" & vbCrLf)
Response.Write("<a href='' style='color: #dcdcdc;' onclick='Mediabox.close();return false;'>Close</a></span></div>" & vbCrLf)
End Sub
End Class
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (2)
Author
Commented:Author
Commented: