This documentation is archived and is not being maintained.

SelectedDatesCollection.Contains Method

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

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

public bool Contains(
	DateTime date
)

Parameters

date
Type: System.DateTime

The System.DateTime to search for in the SelectedDatesCollection.

Return Value

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

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

The following code example demonstrates how to use the Contains method to determine whether the SelectedDatesCollection collection contains the specified System.DateTime object.

<%@ 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>

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: