Event Calendar [ ASP.NET 2.0 / C# ]

琴英华
2023-12-01

http://www.codeproject.com/useritems/EventCalendar.asp

 

CalendarDefault.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CalendarDefault.aspx.cs" Inherits="CalendarDefault" %>

<%@ Register TagPrefix="ECalendar" Namespace="ExtendedControls" Assembly="EventCalendar" %>

<!DOCTYPE html PUBLIC "-//W 3C //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>Event Calendar [ ASP.NET 2.0 / C# ]</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    &nbsp;<asp:GridView ID="gvSelectedDateEvents" runat="server" Width="100%">

        </asp:GridView>

        <ECalendar:EventCalendar ID="Calendar1" runat="server" BackColor="White" BorderColor="Silver"

            BorderWidth="1px" Font-Names="Verdana"

            Font-Size=" 9pt " ForeColor="Black" Height="500px"

            Width="800px" FirstDayOfWeek="Monday" NextMonthText="Next &gt;" PrevMonthText="&lt; Prev" SelectionMode="DayWeekMonth" ShowGridLines="True" NextPrevFormat="ShortMonth"

            ShowDescriptionAsToolTip="True" BorderStyle="Solid" EventDateColumnName="" EventDescriptionColumnName="" EventHeaderColumnName="" OnSelectionChanged="Calendar1_SelectionChanged">

            <SelectedDayStyle BackColor="#333399" ForeColor="White" />

            <TodayDayStyle BackColor="#CCCCCC" />

            <SelectorStyle BorderColor="#404040" BorderStyle="Solid" />

            <DayStyle HorizontalAlign="Left" VerticalAlign="Top" Wrap="True" />

            <OtherMonthDayStyle ForeColor="#999999" />

            <NextPrevStyle Font-Size=" 8pt " ForeColor="#333333" Font-Bold="True" VerticalAlign="Bottom" />

            <DayHeaderStyle BorderWidth="1px" Font-Bold="True" Font-Size=" 8pt " />

            <TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" Font-Bold="True"

                Font-Size=" 12pt " ForeColor="#333399" HorizontalAlign="Center" VerticalAlign="Middle" />

        </ECalendar:EventCalendar>

    </div>

    </form>

</body>

</html>

 

CalendarDefault.aspx.cs

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

 

public partial class CalendarDefault : System.Web.UI.Page

{

    private DataTable GetEvents()

    {

        DataTable dt = new DataTable();

        dt.Columns.Add("EventDate", Type.GetType("System.DateTime"));

        dt.Columns.Add("EventHeader", Type.GetType("System.String"));

        dt.Columns.Add("EventDescription", Type.GetType("System.String"));

 

        DataRow dr;

 

        // Last Week's Events

        dr = dt.NewRow();

        dr["EventDate"] = DateTime.Now.AddDays(-7);

        dr["EventHeader"] = "My Last Week's Event 1";

        dr["EventDescription"] = "My Last Week's Event 1 Description";

        dt.Rows.Add(dr);

 

        // Yesterday's Events

        dr = dt.NewRow();

        dr["EventDate"] = DateTime.Now.AddDays(-1);

        dr["EventHeader"] = "My Yesterday's Event 1";

        dr["EventDescription"] = "My Yesterday's Event 1 Description";

        dt.Rows.Add(dr);

 

        // Todays Events

        dr = dt.NewRow();

        dr["EventDate"] = DateTime.Now;

        dr["EventHeader"] = "My Todays Event 1";

        dr["EventDescription"] = "My Todays Event 1 Description";

        dt.Rows.Add(dr);

 

        dr = dt.NewRow();

        dr["EventDate"] = DateTime.Now;

        dr["EventHeader"] = "My Todays Event 2";

        dr["EventDescription"] = "My Todays Event 2 Description";

        dt.Rows.Add(dr);

 

        // Tomorrow's Events

        dr = dt.NewRow();

        dr["EventDate"] = DateTime.Now.AddDays(1);

        dr["EventHeader"] = "My Tomorrow's Event 1";

        dr["EventDescription"] = "My Tomorrow's Event 1 Description";

        dt.Rows.Add(dr);

 

        return dt;

    }

 

    protected void Page_Load(object sender, EventArgs e)

    {

        Calendar1.EventDateColumnName = "EventDate";

        Calendar1.EventDescriptionColumnName = "EventDescription";

        Calendar1.EventHeaderColumnName = "EventHeader";

 

        Calendar1.EventSource = GetEvents();

    }

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)

    {

        SelectedDatesCollection theDates = Calendar1.SelectedDates;

        DataTable dtEvents = Calendar1.EventSource;

 

        DataTable dtSelectedDateEvents = dtEvents.Clone();

        DataRow dr;

 

        foreach (DataRow drEvent in dtEvents.Rows)

            foreach (DateTime selectedDate in theDates)

                if ((Convert.ToDateTime(drEvent[Calendar1.EventDateColumnName])).ToShortDateString() == selectedDate.ToShortDateString())

                {

                    dr = dtSelectedDateEvents.NewRow();

                    dr[Calendar1.EventDateColumnName] = drEvent[Calendar1.EventDateColumnName];

                    dr[Calendar1.EventHeaderColumnName] = drEvent[Calendar1.EventHeaderColumnName];

                    dr[Calendar1.EventDescriptionColumnName] = drEvent[Calendar1.EventDescriptionColumnName];

                    dtSelectedDateEvents.Rows.Add(dr);

                }

 

        gvSelectedDateEvents.DataSource = dtSelectedDateEvents;

        gvSelectedDateEvents.DataBind();

    }

}

 

 
 类似资料: