Calendar demo

Source of: AddAppointments.aspx
<script runat="server">

    protected void AddButton_Click(object sender, EventArgs e) {
        Appointment ap1 = new Appointment();
        ap1.Start = DateTime.Today+new TimeSpan(9, 0, 0);
        ap1.End = DateTime.Today+new TimeSpan(11, 0, 0);
        ap1.ResourceIndex = 2;
        ap1.Text = "First appointment";
        Calendar.Appointments.Add(ap1);

        Appointment ap2 = new Appointment();
        ap2.Start = DateTime.Today.AddDays(1);
        ap2.End = DateTime.Today.AddDays(1);
        ap2.AllDayEvent = true;
        ap2.ResourceIndex = 1;
        ap2.Text = "Second appointment";
        Calendar.Appointments.Add(ap2);
    }

    protected void AppointmentMenu_Command(object sender, ActionEventArgs e) {
        switch (e.Name) {
            case "deleteitem": {
                    Appointment ap = Calendar.ClickedAppointment;
                    if (ap!=null)
                        Calendar.Appointments.Remove(ap);
                    break;
                } 
        }
    }

    protected void Calendar_CellClick(object sender, CellClickEventArgs e) {
        //
        // Adding a new appointment object after double-click on the calendar grid.
        //
        Appointment ap = new Appointment();
        ap.Text = "New appointment";
        ap.Start = e.DateTime;
        ap.ResourceIndex = e.ResourceIndex;
        ap.AllDayEvent = e.AllDay;
        if (e.AllDay)
            ap.End = ap.Start.AddDays(1);
        else
            ap.End = ap.Start.AddHours(1);
        Calendar.Appointments.Add(ap);
    }

    </script>
<table width="100%">
    <tr>
        <td>
            <goc:DailyCalendar ID="Calendar" runat="server" BorderColor="Black" Font-Names="Verdana"
                Font-Size="Small" Height="348px" Width="500px" VisibleDays="2" OnCellClick="Calendar_CellClick">
                <DateBarStyle Font-Bold="False" Font-Italic="False" HorizontalAlign="Center" ResourceImage="Gray" />
                <AllDayBarStyle BackColor="DarkGray" />
                <DefaultAllDayAppointmentStyle BackColor="White" />
                <ResourceBarStyle Font-Bold="False" Font-Italic="False" Font-Size="X-Small" HorizontalAlign="Center"
                    ResourceImage="Blue" />
                <HoursBarStyle BackColor="WhiteSmoke" Font-Names="Arial" Font-Size="Small" />
                <PreviousDayButton>
                    <Style Font-Underline="True" />
                </PreviousDayButton>
                <NextDayButton>
                    <Style Font-Underline="True" />
                </NextDayButton>
                <DefaultAppointmentStyle BackColor="White" Font-Size="X-Small" ContextMenuID="AppointmentMenu" />
            </goc:DailyCalendar>
            <go:ContextMenuBox ID="AppointmentMenu" runat="server" Font-Names="Verdana" Font-Size="Small" OnCommand="AppointmentMenu_Command" >
                <EventCommand UseCallback="False" />
                <Items>
                    <go:MenuActionItem CommandName="deleteitem" Text="Delete appointment">
                    </go:MenuActionItem>
                </Items>
            </go:ContextMenuBox>
        </td>
        <td valign="top">
               This example shows how to add appointment that will take 2 hours (from 9:00 to 11:00) today 
               and an all-day appointment tomorrow (one day).<br />
            
            <asp:Button ID="AddButton" runat="server" OnClick="AddButton_Click" Text="Add appointments"
                Width="140px" /><br />
            <br />
            You can add a new appointment object (with 1 hour interval) by double clicking an
            empty cell at the calendar grid as well.
            <br />
            <br />
            You can also remove an appointment. Click the appointment�s rectangle with the right
            mouse button and choose �Delete appointment� item.</td>
    </tr>
</table>

(C) ComponentGo! 2010 | Home | Site map | Partners | Links | Forum | info@componentgo.com