1
我想讓VB.net及其日曆更舒適一些。我已將代碼編碼到有幾個事件顯示的日曆,如果您選擇一天或更改月份,則日曆上方的標籤會反映這些更改。我想要做的是允許用戶添加新的事件到計劃中。目前我不知道如何讓新的事件顯示在日曆上。如何獲取日曆上顯示的新事件
代碼:
Public Class Calendar
Inherits System.Web.UI.Page
Dim schedule As New Hashtable
Dim _scheduleData As Hashtable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
_scheduleData = GetSchedule()
Calendar1.Caption = "Personal Schedule"
Calendar1.FirstDayOfWeek = WebControls.FirstDayOfWeek.Sunday
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth
Calendar1.TitleFormat = TitleFormat.MonthYear
Calendar1.ShowGridLines = True
Calendar1.DayStyle.HorizontalAlign = HorizontalAlign.Left
Calendar1.DayStyle.VerticalAlign = VerticalAlign.Top
Calendar1.DayStyle.Height = New Unit(75)
Calendar1.DayStyle.Width = New Unit(100)
Calendar1.OtherMonthDayStyle.BackColor = Drawing.Color.DarkSlateBlue
Calendar1.TodaysDate = New DateTime(2011, 2, 1)
Calendar1.VisibleDate = Calendar1.TodaysDate
End Sub
Private Function GetSchedule() As Hashtable
schedule("2/14/2011") = "Valentines Day"
schedule("2/1/2011") = "Presentation"
schedule("5/16/2011") = "Birthday"
Return schedule
End Function
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
If Not _scheduleData(e.Day.Date.ToShortDateString()) Is Nothing Then
Dim lit = New Literal()
lit.Text = "<br />"
e.Cell.Controls.Add(lit)
Dim lbl = New Label()
lbl.Text = _scheduleData(e.Day.Date.ToShortDateString())
lbl.Font.Size = New FontUnit(FontSize.Small)
e.Cell.Controls.Add(lbl)
End If
End Sub
Private Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
LabelAction.Text = "Selection changed to: " + Calendar1.SelectedDate.ToShortDateString
End Sub
Private Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles Calendar1.VisibleMonthChanged
LabelAction.Text = "Month changed to: " + e.NewDate.ToShortDateString()
End Sub
Private Sub addButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles addButton.Click
Dim day As Date
Dim name As String
day = dayText.Text
name = nameText.Text
schedule(day) = name
End Sub
End Class
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Calendar.aspx.vb" Inherits="WebApplication2.Calendar" %>
<!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">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="LabelAction" runat="server"></asp:Label>
<br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<asp:Label ID="Label1" runat="server" Text="Date"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Name of Event"></asp:Label>
<br />
<asp:TextBox ID="dayText" runat="server" Width="66px"></asp:TextBox>
<asp:TextBox ID="nameText" runat="server"></asp:TextBox>
<asp:Button ID="addButton" runat="server" Text="Add Event" />
</div>
</form>
</body>
</html>
您是否將時間表保存在數據庫或xml文件中 – Kronass 2011-02-01 05:09:53