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

SelectedDatesCollection.SelectRange Method

Adds the specified range of dates to the SelectedDatesCollection.

[Visual Basic]
Public Sub SelectRange( _
   ByVal fromDate As DateTime, _
   ByVal toDate As DateTime _
)
[C#]
public void SelectRange(
 DateTime fromDate,
 DateTime toDate
);
[C++]
public: void SelectRange(
 DateTime fromDate,
 DateTime toDate
);
[JScript]
public function SelectRange(
   fromDate : DateTime,
 toDate : DateTime
);

Parameters

fromDate
A System.DateTime that specifies the initial date to add to the SelectedDatesCollection.
toDate
A System.DateTime that specifies the end date to add to the SelectedDatesCollection.

Remarks

Use this method to add the specified range of dates to the SelectedDatesCollection.

Example

[Visual Basic, C#] The following example demonstrates how to programmatically use the SelectRange method to select a range of continuous dates on the Calendar control.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
 
   <script runat="server">

      Sub Page_Load(sender As Object, e As EventArgs)

         ' Initialize the VisibleDate property with today's date when
         ' the page is first loaded.
         If Not IsPostBack Then

            Calendar1.VisibleDate = Calendar1.TodaysDate

         End If

      End Sub
 
      Sub Button_Click(sender As Object, e As EventArgs) 
 
         ' This method demonstrates how to select a range of dates
         ' in the calendar. 
  
         ' Get the month and year of the date contained in the 
         ' VisibleDate property.
         Dim CurrentMonth As Integer = Calendar1.VisibleDate.Month
         Dim CurrentYear As Integer = Calendar1.VisibleDate.Year

         ' Set the start and end dates.
         Dim BeginDate As DateTime = New DateTime(CurrentYear, CurrentMonth, 1)
         Dim EndDate As DateTime = New DateTime(CurrentYear, CurrentMonth, 7)
 
         ' Clear any selected dates.
         Calendar1.SelectedDates.Clear() 
 
         ' Select the specified range of dates.
         Calendar1.SelectedDates.SelectRange(BeginDate, EndDate)
 
      End Sub
 
   </script>
 
</head>     
<body>
 
   <form runat="server">

      <h3>SelectedDatesCollection SelectRange Example </h3>

      Click the button to select all dates between the 1st and the 
      7th of the month.

      <br><br>
 
      <asp:Calendar ID="Calendar1"  
           SelectionMode="DayWeekMonth"
           runat="server" />
 
      <hr>
 
      <asp:Button id="SubmitButton"
           Text="Select the 1st to the 7th of the Month" 
           OnClick="Button_Click"  
           runat="server"  /> 
       
      <br>
 
      <asp:Label id="Message" 
           runat="server" />
 
   </form>

</body>
</html>
 

[C#] 
<%@ 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 a range of 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;

         // Set the start and end dates.
         DateTime BeginDate = new DateTime(CurrentYear, CurrentMonth, 1);
         DateTime EndDate = new DateTime(CurrentYear, CurrentMonth, 7);
 
         // Clear any selected dates.
         Calendar1.SelectedDates.Clear(); 
 
         // Select the specified range of dates.
         Calendar1.SelectedDates.SelectRange(BeginDate, EndDate);
 
      }
 
   </script>
 
</head>     
<body>
 
   <form runat="server">

      <h3>SelectedDatesCollection SelectRange Example </h3>

      Click the button to select all dates between the 1st and the
      7th of the month.

      <br><br>
 
      <asp:Calendar ID="Calendar1"  
           SelectionMode="DayWeekMonth"
           runat="server" />
 
      <hr>
 
      <asp:Button id="SubmitButton"
           Text="Select the 1st to the 7th of the Month" 
           OnClick="Button_Click"  
           runat="server"  /> 
       
      <br>
 
      <asp:Label id="Message" 
           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 | Calendar

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.