Calendar.SelectionMode Property

 

Gets or sets the date selection mode on the Calendar control that specifies whether the user can select a single day, a week, or an entire month.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public CalendarSelectionMode SelectionMode { get; set; }

Property Value

Type: System.Web.UI.WebControls.CalendarSelectionMode

One of the CalendarSelectionMode values. The default value is Day.

Exception Condition
ArgumentOutOfRangeException

The specified selection mode is not one of the CalendarSelectionMode values.

Use the SelectionMode property to specify the date selection mode on the Calendar control. This property is set with one of the CalendarSelectionMode enumeration values. You can specify whether the user can select a single day, a week, or an entire month, or you can disable date-selection capability entirely.

When this property is set to CalendarSelectionMode.DayWeek or CalendarSelectionMode.DayWeekMonth, an additional selector column that contains week and month selection controls is displayed in the first column of the Calendar control. Use the SelectorStyle property to customize the appearance of this column.

To disable date selection, set this property to CalendarSelectionMode.None.

The following code example demonstrates how to use the SelectionMode property to allow date selection by a single day, a week, or an entire month.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!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>
    <title>Calendar Example</title>
</head>
<body>

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

      <h3>Calendar Example</h3>

      <asp:Calendar id="calendar1" runat="server"
           SelectionMode="DayWeekMonth"/>

   </form>


</body>
</html>

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

<!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" >
   <script runat="server" >

      void Selection_Change(Object sender, EventArgs e)
      {

         // Set the day selection mode.
         Calendar1.SelectionMode = 
            (CalendarSelectionMode)ModeList.SelectedIndex;

      }

   </script>

<head runat="server">
    <title> Calendar SelectionMode Example </title>
</head>
<body>

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

      <h3> Calendar SelectionMode Example </h3>

      Choose the date selection mode.

      <br /><br /> 

      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br /><br />

      <table cellpadding="5">

         <tr>

            <td>

               Mode:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ModeList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">

                  <asp:ListItem> None </asp:ListItem>
                  <asp:ListItem Selected="True"> Day </asp:ListItem>
                  <asp:ListItem> DayWeek </asp:ListItem>
                  <asp:ListItem> DayWeekMonth </asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

      </table>

   </form>

</body>
</html>

.NET Framework
Available since 1.1
Return to top
Show: