Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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
)
public boolean Contains (
	DateTime date
)
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.

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

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

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.