次の方法で共有


SelectedDatesCollection.Contains(DateTime) メソッド

定義

指定した SelectedDatesCollection オブジェクトが DateTime コレクションに格納されているかどうかを示す値を返します。

public:
 bool Contains(DateTime date);
public bool Contains (DateTime date);
member this.Contains : DateTime -> bool
Public Function Contains (date As DateTime) As Boolean

パラメーター

date
DateTime

DateTime で検索する SelectedDatesCollection

戻り値

指定した DateTimeSelectedDatesCollection に含まれている場合は true。それ以外の場合は false

次のコード例では、 メソッドを使用して、Containsコレクションに指定したSystem.DateTimeオブジェクトがSelectedDatesCollection含まれているかどうかを判断する方法を示します。

<%@ 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 Button_Click(Object sender, EventArgs e) 
       {
   
          int current_month = Calendar1.VisibleDate.Month;
          int current_year = Calendar1.VisibleDate.Year;
           
          Calendar1.VisibleDate = Calendar1.TodaysDate;
 
          DateTime date = new DateTime(current_year, current_month, 15);
 
          if (Calendar1.SelectedDates.Contains(date)) 
             Label1.Text = "Yes, you selected the 15th!!";
          else
             Label1.Text = "No, you didn't select the 15th!!";
             
       }
 
    </script>
 
 </head>     
 <body>
 
    <form id="form1" runat="server">
 
       <asp:Calendar ID="Calendar1" runat="server"  
            SelectionMode="DayWeekMonth"/>
 
       <hr />
 
       Select dates on the Calendar and click the button below <br />
       to validate that the 15th on the month was selected <br /><br /> 
 
       <asp:Button id="Button1"
            text="Validate the 15th" 
            OnClick="Button_Click"  
            runat="server"  /> <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 Button_Click(sender As Object, e As EventArgs)
            
            Dim current_month As Integer = Calendar1.VisibleDate.Month
            Dim current_year As Integer = Calendar1.VisibleDate.Year
            
            Calendar1.VisibleDate = Calendar1.TodaysDate
            
            Dim theDate As New DateTime(current_year, current_month, 15)
            
            If Calendar1.SelectedDates.Contains(theDate) Then
                Label1.Text = "Yes, you selected the 15th!!"
            Else
                Label1.Text = "No, you didn't select the 15th!!"
            End If 
        End Sub
 
    </script>
 
 </head>     
 <body>
 
    <form id="form1" runat="server">
 
       <asp:Calendar ID="Calendar1" runat="server"  
            SelectionMode="DayWeekMonth"/>
 
       <hr />
 
       Select dates on the Calendar and click the button below <br />
       to validate that the 15th on the month was selected <br /><br /> 
 
       <asp:Button id="Button1"
            text="Validate the 15th" 
            OnClick="Button_Click"  
            runat="server"  /> <br /><br />
 
       <asp:Label id="Label1" runat="server" />
 
    </form>
 </body>
 </html>

注釈

コレクションに指定したSystem.DateTimeオブジェクトがSelectedDatesCollection含まれているかどうかを判断するには、このメソッドを使用します。

適用対象

こちらもご覧ください