Clear Method
Collapse the table of content
Expand the table of content

SelectedDatesCollection.Clear Method

Removes all System.DateTime objects from the collection.

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

public void Clear ()
public void Clear ()
public function Clear ()

Use this method to remove all System.DateTime objects from the SelectedDatesCollection collection and set the Count property to 0.

The following code example demonstrates how to use the Clear method to remove all System.DateTime objects from the SelectedDatesCollection collection and replace them with new System.DateTime objects.

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

<html>
<head>
 
   <script runat="server">

      void Page_Load(Object sender, EventArgs e)
      {

         // Initialize the VisibleDate property with today's date when
         // the page is first loaded.
         if(!IsPostBack)
         {

            Calendar1.VisibleDate = Calendar1.TodaysDate;

         }

      }
     
      void Button_Click(Object sender, EventArgs e) 
      {

         // This method demonstrates how to select noncontiguous dates 
         // in the calendar. 
  
         // Get the month and year of the date contained in the 
         // VisibleDate property.
         int CurrentMonth = Calendar1.VisibleDate.Month;
         int CurrentYear = Calendar1.VisibleDate.Year;
   
         // Clear all selected dates.
         Calendar1.SelectedDates.Clear();
   
         // Iterate through the current month and add all Wednesdays 
         // to the collection.
         for (int i = 1; 
             i <= System.DateTime.DaysInMonth(CurrentYear, CurrentMonth);
              i++)
         {

            DateTime CurrentDate = new DateTime(CurrentYear, CurrentMonth, i);

            if (CurrentDate.DayOfWeek == DayOfWeek.Wednesday)
            {
               Calendar1.SelectedDates.Add(CurrentDate);
            }

         }
 
         // Display the number of items selected.
         Message.Text = "Selection Count = " + 
             Calendar1.SelectedDates.Count.ToString();
 
      }
 
      void Selection_Change(Object sender, EventArgs e) 
      {

         // Display the number of items selected.
         Message.Text = "Selection Count = " + 
             Calendar1.SelectedDates.Count.ToString();

      }
 
   </script>
 
</head>     
<body>
 
   <form runat="server">

      <h3>SelectedDatesCollection Add Example </h3>

      Click the button to select all Wednesdays in the month.

      <br><br>
 
      <asp:Calendar ID="Calendar1" runat="server"  
           SelectionMode="DayWeekMonth" 
           OnSelectionChanged="Selection_Change" />
 
      <hr>
 
      <asp:Button id="SubmitButton"
           Text="Select All Weds in Month" 
           OnClick="Button_Click"  
           runat=server  /> 

      <br>
 
      <asp:Label id="Message" 
           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

Community Additions

ADD
Show:
© 2016 Microsoft