This documentation is archived and is not being maintained.

SelectedDatesCollection.Contains Method

Returns a value indicating whether the SelectedDatesCollection contains the specified System.DateTime.

[Visual Basic]
Public Function Contains( _
   ByVal date As DateTime _
) As Boolean
[C#]
public bool Contains(
 DateTime date
);
[C++]
public: bool Contains(
 DateTime date
);
[JScript]
public function Contains(
   date : DateTime
) : Boolean;

Parameters

date
The System.DateTime to search for in the SelectedDatesCollection.

Return Value

true if the SelectedDatesCollection contains the specified System.DateTime; otherwise, false.

Remarks

Use this method to determine whether the SelectedDatesCollection contains the specified System.DateTime.

Example

[Visual Basic, C#] The following example demonstrates how to use the Contains method to determine whether the SelectedDatesCollection contains the specified System.DateTime.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
 <head>
 
    <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 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>
    

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

<html>
 <head>
 
    <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 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>
    

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

SelectedDatesCollection Class | SelectedDatesCollection Members | System.Web.UI.WebControls Namespace | System.DateTime | SelectedDates | Calendar

Show: