Hello, I'm trying to create a calender control that gets date and title from the events table in an access database. Then display the title for a given date in a linkbutton or hyperlink so that when the link is displayed and then clicked by the user I can then grab the corresponding event data and populate a datalist. Using the code below that I modified from
http://msdn2.microsoft.com/en-us/library/ms228044(VS.80).aspx I was able to display the dates that have an event. Now I need help displaying the title in the linkbutton. How can this be accomplished? Any help would be great!
Here is the code that I'm working with:
Protected dsEvents As DataSet
Protected Sub FillEventsDataset()
Dim firstDate As New DateTime(calHREvents.Visib
leDate.Yea
r, _
calHREvents.VisibleDate.Mo
nth, 1)
Dim lastDate As DateTime = GetFirstDayOfNextMonth()
dsEvents = GetCurrentMonthData(firstD
ate, lastDate)
End Sub
Protected Function GetFirstDayOfNextMonth() As DateTime
Dim monthNumber, yearNumber As Integer
If calHREvents.VisibleDate.Mo
nth = 12 Then
monthNumber = 1
yearNumber = calHREvents.VisibleDate.Ye
ar + 1
Else
monthNumber = calHREvents.VisibleDate.Mo
nth + 1
yearNumber = calHREvents.VisibleDate.Ye
ar
End If
Dim lastDate As New DateTime(yearNumber, monthNumber, 1)
Return lastDate
End Function
Protected Sub calHREvents_VisibleMonthCh
anged(ByVa
l sender As Object, _
ByVal e As System.Web.UI.WebControls.
MonthChang
edEventArg
s) _
Handles calHREvents.VisibleMonthCh
anged
FillEventsDataset()
End Sub
Function GetCurrentMonthData(ByVal firstDate As DateTime, _
ByVal lastDate As DateTime) As DataSet
Dim dsMonth As New DataSet
'create connection to HRData database
Dim objConn As OleDbConnection = New OleDbConnection("Provider=
Microsoft.
Jet.OLEDB.
4.0; data source=" & Server.MapPath("~/App_Data
/HRData.md
b"))
Dim connString As String = objConn.ConnectionString
Dim dbConnection As New OleDbConnection(connString
)
Dim query As String
query = "SELECT Date, Title FROM Events " & _
" WHERE Date >= @firstDate AND Date < @lastDate"
Dim dbCommand As New OleDbCommand(query, dbConnection)
dbCommand.Parameters.Add(N
ew OleDbParameter("@firstDate
", firstDate))
dbCommand.Parameters.Add(N
ew OleDbParameter("@lastDate"
, lastDate))
Dim oleDataAdapter As New OleDbDataAdapter(dbCommand
)
Try
oleDataAdapter.Fill(dsMont
h)
Catch
End Try
Return dsMonth
End Function
Protected Sub calHREvents_DayRender(ByVa
l sender As Object, _
ByVal e As System.Web.UI.WebControls.
DayRenderE
ventArgs) _
Handles calHREvents.DayRender
Dim nextDate As DateTime
If Not dsEvents Is Nothing Then
For Each dr As DataRow In dsEvents.Tables(0).Rows
nextDate = CType(dr("Date"), DateTime)
If nextDate = e.Day.Date Then
e.Cell.BackColor = System.Drawing.Color.Pink
End If
Next
End If
End Sub
Here is the markup:
<asp:Calendar ID="calHREvents" Width="725px" Height="500px" runat="server" BackColor="White" BorderColor="Black" DayNameFormat="Shortest" Font-Names="Times New Roman" Font-Size="10pt" ForeColor="Black" NextPrevFormat="FullMonth"
TitleFormat="Month">
<SelectedDayStyle BackColor="#CC3333" ForeColor="White" />
<TodayDayStyle BackColor="#CCCC99" />
<SelectorStyle BackColor="#CCCCCC" Font-Bold="True" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#333333" Width="1%" />
<DayStyle Width="14%" />
<OtherMonthDayStyle ForeColor="#999999" />
<NextPrevStyle Font-Size="8pt" ForeColor="White" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" ForeColor="#333333"
Height="10pt" />
<TitleStyle BackColor="Black" Font-Bold="True" Font-Size="12pt" ForeColor="White"
Height="10pt" />
</asp:Calendar>