Calendar demo

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

    //
    // Initializes the comboboxes and number of visible resource in text edit.
    //
    protected void Calendar_Load(object sender, EventArgs e) {
        if (!IsPostBack) {
            initHours(ErnestDrop, 9);
            initHours(PeterDrop, 10);
            initHours(SonyaDrop, 11);
        }
        int v;
        if (!int.TryParse(VisibleResourcesTextBox.Text, out v))
            v = 0;
        Calendar.VisibleResources = v;
    }
     
    //
    // Initializes the combobox with the standard hours.
    //
    static void initHours(DropDownList list, int selHour) {
        for (int mins = 0; mins<=24*60; mins += 30) {
            ListItem it = new ListItem();
            it.Text = string.Format("{0:00}:{1:00}", mins/60, mins%60);
            it.Value = mins.ToString();
            it.Selected = mins%60==0 && mins/60==selHour;
            list.Items.Add(it);
        }
    }

    //
    // The handler allows overriding the standard day settings for particularly days. 
    //
    protected void Calendar_GetDayInfo(object sender, GetDayInfoEventArgs e) {
        //
        // The sample implementation of the GetDayInfo event customizes the today. 
        // Causes today is not a free day (holyday, Sunday, etc.) and depend on 
        // resource name sets different work begin hour.
        //
        if (e.Date==DateTime.Today) {
            e.FreeDay = false;
            switch (e.Resource.Text) {
                case "Ernest":
                    e.WorkHourBegin = TimeSpan.FromMinutes(int.Parse(ErnestDrop.SelectedValue));
                    break;
                case "Peter":
                    e.WorkHourBegin = TimeSpan.FromMinutes(int.Parse(PeterDrop.SelectedValue));
                    break;
                case "Sonya":
                    e.WorkHourBegin = TimeSpan.FromMinutes(int.Parse(SonyaDrop.SelectedValue));
                    break;
            }
        }
    }

    //
    // Following code (handler) is invoked every server request, 
    // independently either postback or callback, just before 
    // serializing control state into the client control.
    //
    protected void Calendar_PreSerialize(object sender, EventArgs e) {
        //
        // Initialize the hover flag depends on a state of checkbox.
        //
        if (HoverCheckBox.Checked)
            Calendar.BehaviorOptions |= CalendarBehaviorOptions.HoverEnabled;
        else
            Calendar.BehaviorOptions &= ~CalendarBehaviorOptions.HoverEnabled;

        //
        // Initialize the selecting mode depends on a state of user combobox.
        //
        switch (SelectModeList.Text) {
            case "None": Calendar.SelectMode = SelectMode.None; break;
            case "OneCell": Calendar.SelectMode = SelectMode.OneCell; break;
            case "OneCellAndHour": Calendar.SelectMode = SelectMode.OneCellAndHour; break;
            case "AllDay": Calendar.SelectMode = SelectMode.AllDay; break;
            case "AllRow": Calendar.SelectMode = SelectMode.AllRow; break;
            case "OnlyHour": Calendar.SelectMode = SelectMode.OnlyHour; break;
        }
    }
    
</script>
<table width="100%">
    <tr>
        <td valign="top">
            <goc:DailyCalendar ID="Calendar" runat="server" BorderColor="SaddleBrown" Font-Names="Times New Roman"
                Font-Size="Medium" Height="423px" Width="500px" FreeHourColor="Goldenrod" 
                LineColor="Peru" WorkHourColor="PaleGoldenrod" 
                OnGetDayInfo="Calendar_GetDayInfo" VisibleDays="2" OnLoad="Calendar_Load" 
                OnPreSerialize="Calendar_PreSerialize">
                <DateBarStyle Font-Bold="True" Font-Italic="False" HorizontalAlign="Center" BackColor="Chocolate" ForeColor="OldLace" />
                <AllDayBarStyle BackColor="Chocolate" />
                <DefaultAllDayAppointmentStyle BackColor="White" />
                <ResourceBarStyle Font-Bold="True" Font-Italic="True" HorizontalAlign="Center" BackColor="SaddleBrown" ForeColor="OldLace" />
                <HoursBarStyle BackColor="BurlyWood" Font-Names="Arial" Font-Size="Small" ForeColor="Sienna" />
                <DefaultAppointmentStyle BackColor="White" />
            </goc:DailyCalendar>
        </td>
        <td valign="top">
                A sample shows how to use a GetDayInfo event to independently set working hours for particular day and resource columns.<br />
            <br />
            Select a starting hour for each resource. This setting will be effective only for columns of a current day:<br />
            Ernest:
            <asp:DropDownList ID="ErnestDrop" runat="server" AutoPostBack="True" Width="108px">
            </asp:DropDownList><br />
            Peter:
            <asp:DropDownList ID="PeterDrop" runat="server" AutoPostBack="True" Width="108px">
            </asp:DropDownList><br />
            Sonya:
            <asp:DropDownList ID="SonyaDrop" runat="server" AutoPostBack="True" Width="108px">
            </asp:DropDownList><br />
            <br />
            When you have too many resources to show as the same time in the calendar, you can
            limit number of the displayed resources by changing appropriate property. Default
            value 0 shows all resources in the collection.<br />
            VisibleResources:
            <asp:TextBox ID="VisibleResourcesTextBox" runat="server" Width="78px" AutoPostBack="True">2</asp:TextBox><br />
            <br />
            Determine way how cells are selected and enable or disable hover effect.<br />
            SelectMode:
            <asp:DropDownList ID="SelectModeList" runat="server" Width="137px" AutoPostBack="True">
                <asp:ListItem>None</asp:ListItem>
                <asp:ListItem Selected="True">OneCell</asp:ListItem>
                <asp:ListItem>OneCellAndHour</asp:ListItem>
                <asp:ListItem>AllDay</asp:ListItem>
                <asp:ListItem>AllRow</asp:ListItem>
                <asp:ListItem>OnlyHour</asp:ListItem>
            </asp:DropDownList><br />
            <asp:CheckBox ID="HoverCheckBox" runat="server" Text="HoverEnabled:" TextAlign="Left" Checked="True" AutoPostBack="True" /></td>
    </tr>
</table>

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