SelectedDatesCollection.SelectRange(DateTime, DateTime) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将指定的日期范围添加到 SelectedDatesCollection 集合中。
public:
void SelectRange(DateTime fromDate, DateTime toDate);
public void SelectRange (DateTime fromDate, DateTime toDate);
member this.SelectRange : DateTime * DateTime -> unit
Public Sub SelectRange (fromDate As DateTime, toDate As DateTime)
参数
- fromDate
- DateTime
一个 DateTime,它指定添加到 SelectedDatesCollection 的初始日期。
- toDate
- DateTime
一个 DateTime,它指定添加到 SelectedDatesCollection 的结束日期。
示例
下面的代码示例演示如何以编程方式使用 SelectRange 该方法在控件上 Calendar 选择一系列连续日期。
<%@ 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>SelectedDatesCollection SelectRange Example </title>
<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 id="form1" 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>
<%@ Page Language="VB" 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>SelectedDatesCollection SelectRange Example </title>
<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 id="form1" 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>
注解
使用此方法可将指定的日期范围添加到 SelectedDatesCollection 集合中。