mlawrence
03-10-2004, 02:32 AM
This is an excellent forum for aspx questions:
http://www.asp.net/Forums/default.aspx
27lamps
03-10-2004, 07:54 AM
Hello,
i create an ASP.net page where i inserted the Calendar control.
Now i am trying to fill the calendar with events from an Access Database.
I am having problems with it. Did anyone ever did something like this in ASP.net / VB? Can u help me out, send me some code, control or DW extension? Anything?
Thank You Very Much,
Miguel
Cheers,
Miguel
.web: http://www.27lamps.com
.email: internet@27lamps.com
nature
04-05-2004, 11:04 AM
Hi,
I created a calendar using this article: http://aspnet.4guysfromrolla.com/articles/041603-1.2.aspx
THis site tends to have very informative articles.
I got it to work after tinkering for a while. Here's what I ended up with. Hope it helps.
<%@ Page Language="VB" %>
<script runat="server">
Public Structure MyDates
Dim _Title as String
Dim _Date as DateTime
Dim _Id as String
End Structure
Public MyCollection As Collection
Public tempDate As DateTime
Public Sub Page_Load()
tempDate = Calendar1.TodaysDate
If Not (Page.IsPostBack) Then
Get_DBItems()
End if
End Sub
Public Sub Get_DBItems()
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim myStartDate = tempDate.AddDays(-31) '-5
Dim mySQL = "SELECT e_title, e_event_id, e_event_status, e_date_start FROM event_detail where e_date_start >=" + "#"+ myStartDate +"#"+ " and e_event_status = 'A' order by e_date_start desc"
myConnection = New OleDbConnection(ConfigurationSettings.AppSettings("ConnectionString") )
myCommand = New OleDbCommand(mySQL , myConnection)
'// Set to 40 days before the current value of tempDate
'//Dim parameterDate As New OleDbParameter("@_Date", OleDbDbType.DateTime, 8)
'// parameterDate.Value = tempDate.AddDays(-40)
'// myCommand.Parameters.Add(parameterDate)
'// Set to 40 days after the current value of tempDate
'//Dim parameterDate2 As New OleDbParameter("@_Date_Plus_1", OleDbDbType.DateTime, 8)
'// parameterDate2.Value = tempDate.AddDays(40)
'// myCommand.Parameters.Add(parameterDate2)
Dim myDataReader As OleDbDataReader
myConnection.Open()
myDataReader = myCommand.ExecuteReader()
Dim temp As MyDates
MyCollection = New Collection()
While(myDataReader.Read())
'//Created each time through the loop to get a new item to load and add to the collection
temp = New MyDates()
temp._Title = myDataReader.Item("e_title")
temp._Date = CDate(myDataReader.Item("e_date_start"))
temp._Id = myDataReader.Item("e_event_id")
MyCollection.Add(temp)
End While
'// Close
myDataReader.Close()
myConnection.Close()
End Sub
Private Sub Calendar1_DayRender(sender As Object, e As DayRenderEventArgs)
Dim Item as MyDates '//Temporary storage for looping through the collection
Dim TextColor as String
Dim DayHold as DateTime = "01/01/1900" '//Temporary date to check for multiple items per day
Dim MultipleItemDay as Boolean = False
'// Set to true if the date is in the collection and needs to be displayed
Dim DayTextHasChanged As Boolean = False
'//To build the string for the contents of the table cell
'//I'll use the stingbuilder class instead of concatenation
Dim temp as StringBuilder
dim StrUrl as String
For Each Item In MyCollection
'//The collection is loaded in date order. So, if the date is different than the DayHold variable
'//And I've already found the right day in the collection, I can exit the for loop
If DayHold <> Item._Date Then
If DayTextHasChanged = True
Exit for
End if
MultipleItemDay = False
DayHold = Item._Date
Else
MultipleItemDay = True
End if
'//If I've found a date matching the current date...I need to create the appropriate text
If e.Day.Date = Item._Date.ToString("d") Then
If MultipleItemDay = False Then
temp = New StringBuilder() '//Create a new stringbuilder object
Else
temp.Append("
") '//add a seperator to the stringbuilder
End If
'StrUrl = "<A HREF=../Event/detail_rolla.asp?id=" '+<%= Server.URLEncode(Item._Title.ToString())%> +"TARGET=_self>"+Item._Title.ToString() +"
"
'"<a href=../Event/event_detail.asp?id="+<%= Server.URLEncode(Item._Title.ToString())%>+"></a><a href="aboutus/purpose.asp">
'StrUrl = "<a href=../Event/event_detail.asp?id="+<%= Server.URLEncode(Item._Title.ToString())%>+" TARGET=_self>"+Item._id.ToString()+"</a>"
StrUrl = "<a href=../Event/event_detail.aspx?EventID="+Server.URLEncode(Item._Id.ToString())+" TARGET=_self>"+Item._Title.ToString()+"</a>"
temp.Append("<span style=""font-family:Arial; font-weight:bold;font-size:12px; color:")
temp.Append(TextColor)
temp.Append(""">
")
temp.Append(StrUrl )
temp.Append("</span>")
DayTextHasChanged = True '//Set the flag
End If
Next
'//If there was an Item for this day, add the stringbuilder text to the table cell
If DayTextHasChanged = True then
e.Cell.Controls.Add(New LiteralControl(temp.ToString()))
End If
End Sub
'don't understand this
Private Sub Calendar1_SelectionChanged(sender As Object, e As EventArgs)
response.redirect("eventUpdate2.aspx?action=ADD")
' Dim myConnection As OleDbConnection
' Dim myCommand As OleDbCommand
' Dim myDataReader As OleDbDataReader
' myConnection = New OleDbConnection( ConfigurationSettings.AppSettings("ConnectionString") )
' myCommand = New OleDbCommand("Intranet_sp_Marketing_Get_Items_For_Single_Date", myConnection)
' myCommand.CommandType = CommandType.StoredProcedure
' /Dim parameter_Date As New OleDbParameter("@_Date", OleDbDbType.DateTime, 8)
' / parameter_Date.Value = Calendar1.SelectedDate
' / myCommand.Parameters.Add(parameter_Date)
' myConnection.Open()
' myDataReader = myCommand.ExecuteReader()
'Dim temp As String = ""
'Dim Category as String
'While(myDataReader.Read())
' temp &= "Title : <a href=""edit.aspx?ID=" & myDataReader.Item("Id") & """>" & myDataReader.Item("e_title") & "</a>
Date : " & myDataReader.Item("_Date") & "
Promotion Type : " & myDataReader.Item("Type") & "
Audience : " & myDataReader.Item("Audience") & "
Person Responsible : " & myDataReader.Item("PersonResponsible") & "
"
'End While
'daydetail.Visible = True
'daydetail_render.InnerHTML = temp
'myDataReader.Close()
'myConnection.Close()
'selectedday.InnerHTML = Calendar1.SelectedDate.ToString("MMM d, yyyy")
'tempDate = Calendar1.SelectedDate '//
'Get_DBItems()
End Sub
Private Sub MonthChanged(source As Object, e As MonthChangedEventArgs)
'//Set the tempDatevariable to the value in the MonthChangedEventArgs NewDate property
tempDate = e.NewDate
'//Reload the collection
Get_DBItems()
End Sub
</script>
<!-- #include virtual="/include/header.aspx" -->
<html>
<head>
<SOCIABLES:HEADER id="Header" style="Z-INDEX: 100" runat="server"></SOCIABLES:HEADER>
</head>
[b]
<form runat="server">
<div id="daydetail" runat="server" visible="false">
</div>
<span id="selectedday" runat="server"><span id="daydetail_render" runat="server">
<asp:Calendar id="Calendar1" Width="100%" DayHeaderStyle-Font-Name="Verdana" Height="600" TodayDayStyle-ForeColor="Black" DayStyle-BorderWidth="1" DayStyle-BorderStyle="Solid" OtherMonthDayStyle-ForeColor="#C0C0C0" SelectedDayStyle-ForeColor="#000000" SelectedDayStyle-BackColor="#faebd7" Runat="server" CellPadding="0" BorderColor="#000000" BackColor="white" TitleStyle-Font-Size="12" TitleStyle-Font-Name="Verdana" TitleStyle-Font-Bold="False" SelectionMode="Day" NextPrevFormat="FullMonth" DayStyle-Font-Size="12" DayStyle-Font-Name="Arial" DayStyle-verticalalign="Top" DayStyle-HorizontalAlign="Left" DayStyle-Width="14%" DayStyle-Height="100" OnVisibleMonthChanged="MonthChanged" FirstDayOfWeek="Monday" OnDayRender="Calendar1_DayRender" OnSelectionChanged="Calendar1_SelectionChanged">
<TodayDayStyle forecolor="Black"></TodayDayStyle>
<DayStyle font-size="12pt" font-names="Arial" horizontalalign="Left" height="100px" borderwidth="1px" borderstyle="Solid" width="14%" verticalalign="Top"></DayStyle>
<DayHeaderStyle font-names="Verdana"></DayHeaderStyle>
<SelectedDayStyle forecolor="Black" backcolor="AntiqueWhite"></SelectedDayStyle>
<TitleStyle font-size="12pt" font-names="Verdana"></TitleStyle>
<OtherMonthDayStyle forecolor="Silver"></OtherMonthDayStyle>
</asp:Calendar>
<!-- '//OnSelectionChanged="Calendar1_SelectionChanged" -->
[b]
[b]
</span></span>>
</form>
</body>
</html>
vBulletin® ©Jelsoft Enterprises Ltd.