Calendar.SelectionMode 屬性

定義

取得或設定 Calendar 控制項上的日期選取模式,指定使用者是否可以選取單一日、週或整個月份。

public:
 property System::Web::UI::WebControls::CalendarSelectionMode SelectionMode { System::Web::UI::WebControls::CalendarSelectionMode get(); void set(System::Web::UI::WebControls::CalendarSelectionMode value); };
[System.ComponentModel.Bindable(true)]
public System.Web.UI.WebControls.CalendarSelectionMode SelectionMode { get; set; }
public System.Web.UI.WebControls.CalendarSelectionMode SelectionMode { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.SelectionMode : System.Web.UI.WebControls.CalendarSelectionMode with get, set
member this.SelectionMode : System.Web.UI.WebControls.CalendarSelectionMode with get, set
Public Property SelectionMode As CalendarSelectionMode

屬性值

其中一個 CalendarSelectionMode 值。 預設值是 Day

屬性

例外狀況

指定的選取模式不是其中一個 CalendarSelectionMode 值。

範例

下列程式碼範例示範如何使用 SelectionMode 屬性,允許以單一日期、一周或整個月選取日期。

<%@ 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="VB" 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>
<%@ Page Language="VB" 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" >
  
      Sub Selection_Change(sender As Object, e As EventArgs)

         ' Set the day selection mode.
         Calendar1.SelectionMode = _
            CType(ModeList.SelectedIndex, CalendarSelectionMode)

      End Sub
  
   </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>

備註

SelectionMode使用 屬性來指定控制項上的 Calendar 日期選取模式。 這個屬性是使用其中 CalendarSelectionMode 一個列舉值來設定。 您可以指定使用者是否可以選取單一天、一周或整個月,或完全停用日期選取功能。

當這個屬性設定為 CalendarSelectionMode.DayWeekCalendarSelectionMode.DayWeekMonth 時,包含周和月選取控制項的其他選取器資料行會顯示在 控制項的第一個資料行 Calendar 中。 SelectorStyle使用 屬性來自訂此資料行的外觀。

若要停用日期選取,請將此屬性設定為 CalendarSelectionMode.None

適用於

另請參閱