CalendarDay.IsSelected 屬性

定義

取得值,指出這個類別的執行個體所代表的日期是否在 Calendar 控制項中被選取。 這個屬性是唯讀的。

public:
 property bool IsSelected { bool get(); };
public bool IsSelected { get; }
member this.IsSelected : bool
Public ReadOnly Property IsSelected As Boolean

屬性值

如果這個類別的執行個體所代表的日期在 Calendar 控制項中被選取,則為 true,否則為 false

範例

下列範例示範如何使用 IsSelected 屬性來判斷是否已在 中 Calendar 選取目前的日期。 請注意, Day 傳遞至 DayRender 事件處理常式之 DayRenderEventArgs 物件的 屬性是 CalendarDay 物件。

<%@ 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>ASP.NET Example</title>
<script language="C#" runat="server">

      void DayRender(Object source, DayRenderEventArgs e) 
      {
      
         if (e.Day.IsSelected && e.Day.IsToday)
         {
            Label1.Text = "You selected today's date.";
         }
      
      }

   </script>
 
</head>
 
<body>
 
   <form id="form1" runat="server">
 
      <asp:Calendar id="calendar1" runat="server"
           WeekendDayStyle-BackColor="gray"
           OnDayRender="DayRender"/>

      <br /><br />

      <asp:Label id="Label1" runat="server"/>
                   
   </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>ASP.NET Example</title>
<script language="VB" runat="server">
        Sub DayRender(source As Object, e As DayRenderEventArgs)
            
            If e.Day.IsSelected And e.Day.IsToday Then
                Label1.Text = "You selected today's date."
            End If
        End Sub 'DayRender  
  </script>
 
</head>
 
<body>
 
   <form id="form1" runat="server">
 
      <asp:Calendar id="calendar1" runat="server"
           WeekendDayStyle-BackColor="gray"
           OnDayRender="DayRender"/>

      <br /><br />

      <asp:Label id="Label1" runat="server"/>
                   
   </form>
         
</body>
</html>

備註

IsSelected使用 屬性,以程式設計方式判斷控制項中 Calendar 是否選取這個類別實例所代表的日期。 這允許您根據這個值,以程式設計的方式控制日期的外觀或行為。

適用於

另請參閱