asp.net - Programmatically select multiple dates in a Calendar

Programmatically select multiple dates in Calendar control
Calendar is an asp.net web server control which allow users to select an individual date or multiple dates at a time. even we can programmatically select multiple dates in a calendar server control.

calendar SelectedDatesCollection contains a collection of System.DateTime objects that represent the selected dates in a calendar control. we can add DateTime objects to this collection to programmatically select dates in a calendar control. SelectedDatesCollection class Add() method append the specified System.DateTime object to the end of SelectedDatesCollection collection. Add() method require to pass a parameter name 'date' that type is System.DateTime.

The following asp.net c# example code demonstrate us how can we programmatically select multiple dates in calendar control.
ProgrammaticallySelectCalendarDates.aspx

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
    {
        SelectedDatesCollection dates = Calendar1.SelectedDates;
        dates.Add(new DateTime(2011, 9, 1));
        dates.Add(new DateTime(2011, 9, 5));
        dates.Add(new DateTime(2011, 9, 9));
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to programmatically select multiple dates in Calendar control</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:DodgerBlue; font-style:italic;">
            How to programmatically select multiple dates in Calendar control
        </h2>
        <hr width="675" align="left" color="LightBlue" />
        <asp:Calendar
            ID="Calendar1" 
            runat="server"
            NextPrevFormat="FullMonth"
            SelectionMode="DayWeekMonth"
            SelectMonthText="Month"
            SelectWeekText="Week"
            ForeColor="WhiteSmoke"
            DayNameFormat="Full"
            Font-Names="Book Antiqua"
            Font-Size="Medium"
            >
            <DayHeaderStyle
                 BackColor="DarkOliveGreen"
                 />
            <DayStyle
                 BackColor="DarkKhaki"
                 BorderColor="Khaki"
                 BorderWidth="1"
                 Font-Bold="true"
                 Font-Italic="true"
                 />
            <NextPrevStyle
                 Font-Italic="true"
                 Font-Names="Arial CE"
                 />
            <SelectedDayStyle
                 BackColor="DarkOrange"
                 BorderColor="Orange"
                 />
            <SelectorStyle
                 BackColor="DarkOliveGreen"
                 ForeColor="Snow"
                 Font-Names="Times New Roman Greek"
                 Font-Size="Small"
                 BorderColor="Olive"
                 BorderWidth="1"
                 />
            <TitleStyle
                 BackColor="DarkSlateBlue"
                 Height="35"
                 Font-Size="Large"
                 Font-Names="Courier New Baltic"
                 />
        </asp:Calendar>
    </div>
    </form>
</body>
</html>
More asp.net examples