Export (0) Print
Expand All

SelectedDatesCollection Class

Encapsulates a collection of System.DateTime objects that represent the selected dates in a Calendar control. This class cannot be inherited.

System.Object
  System.Web.UI.WebControls.SelectedDatesCollection

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

public sealed class SelectedDatesCollection : ICollection, 
	IEnumerable

The SelectedDatesCollection type exposes the following members.

  NameDescription
Public methodSelectedDatesCollectionInitializes a new instance of the SelectedDatesCollection class with the specified date list.
Top

  NameDescription
Public propertyCountGets the number of System.DateTime objects in the SelectedDatesCollection collection.
Public propertyIsReadOnlyGets a value indicating whether the SelectedDatesCollection collection is read-only.
Public propertyIsSynchronizedGets a value indicating whether access to the SelectedDatesCollection collection is synchronized (thread safe).
Public propertyItemGets a System.DateTime object at the specified index in the SelectedDatesCollection collection.
Public propertySyncRootGets the object that can be used to synchronize access to the SelectedDatesCollection collection.
Top

  NameDescription
Public methodAddAppends the specified System.DateTime object to the end of the SelectedDatesCollection collection.
Public methodClearRemoves all System.DateTime objects from the collection.
Public methodContainsReturns a value indicating whether the SelectedDatesCollection collection contains the specified System.DateTime object.
Public methodCopyToCopies the items from the SelectedDatesCollection collection to the specified System.Array, starting with the specified index.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetEnumeratorReturns an System.Collections.IEnumerator-implemented object that contains all System.DateTime objects within the SelectedDatesCollection collection.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodRemoveRemoves the specified System.DateTime object from the SelectedDatesCollection collection.
Public methodSelectRangeAdds the specified range of dates to the SelectedDatesCollection collection.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast<TResult>Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

Use this class to programmatically manage a collection of System.DateTime objects that represent the selected dates in a Calendar control. This class is commonly used to add or remove dates from the collection.

This collection stores only whole dates. The time portion of each System.DateTime is removed. The dates are stored in ascending order. If there are duplicate dates, only one date is stored in the collection.

The following code example demonstrates how to programmatically use the SelectedDatesCollection class to select dates in the Calendar control.

<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Page_Load(Object sender, EventArgs e) 
  {
    DisplayCalendar.VisibleDate = DisplayCalendar.TodaysDate;
  }

  void SelectButton_Click(Object sender, EventArgs e) 
  {

    int current_day = DisplayCalendar.VisibleDate.Day;
    int current_month = DisplayCalendar.VisibleDate.Month;
    int current_year = DisplayCalendar.VisibleDate.Year;

    DisplayCalendar.SelectedDates.Clear();

    // Iterate through the current month and add all Wednesdays to the 
    // SelectedDates collection of the Calendar control.
    for (int i = 1; i <= System.DateTime.DaysInMonth(current_year, current_month); i++)
    {
       DateTime currentDate = new DateTime(current_year, current_month, i);
       if (currentDate.DayOfWeek == DayOfWeek.Wednesday)
       {
         DisplayCalendar.SelectedDates.Add(currentDate);
       }
    }

     MessageLabel.Text = "Selection Count = " + DisplayCalendar.SelectedDates.Count.ToString();

  }

  void DisplayCalendar_SelectionChanged(Object sender, EventArgs e) 
  {
    MessageLabel.Text = "Selection Count = " + DisplayCalendar.SelectedDates.Count.ToString();
  }

</script> 

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:calendar id="DisplayCalendar" runat="server"  
        selectionmode="DayWeekMonth" 
        onselectionchanged="DisplayCalendar_SelectionChanged" />

      <hr />

      <asp:button id="SelectButton"
        text="Select All Weds in Month" 
        onclick="SelectButton_Click"  
        runat="server"/> 

      <br/>

      <asp:label id="MessageLabel" 
        runat="server" />

    </form>
  </body>
</html>
   

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft