📅  最后修改于: 2020-11-21 05:48:48             🧑  作者: Mango
日历控件是功能丰富的Web控件,它提供以下功能:
日历控件的基本语法为:
日历控件具有许多属性和事件,您可以使用它们自定义控件的动作和显示。下表提供了Calendar控件的一些重要属性:
Properties | Description | ||
---|---|---|---|
Caption | Gets or sets the caption for the calendar control. | ||
CaptionAlign | Gets or sets the alignment for the caption. | ||
CellPadding | Gets or sets the number of spaces between the data and the cell border. | ||
CellSpacing | Gets or sets the space between cells. | ||
DayHeaderStyle | Gets the style properties for the section that displays the day of the week. | ||
DayNameFormat | Gets or sets format of days of the week. | ||
DayStyle | Gets the style properties for the days in the displayed month. | ||
FirstDayOfWeek | Gets or sets the day of week to display in the first column. | ||
NextMonthText | Gets or sets the text for next month navigation control. The default value is >. | ||
NextPrevFormat | Gets or sets the format of the next and previous month navigation control. | ||
OtherMonthDayStyle | Gets the style properties for the days on the Calendar control that are not in the displayed month. | ||
PrevMonthText | Gets or sets the text for previous month navigation control. The default value is <. | ||
SelectedDate | Gets or sets the selected date. | ||
SelectedDates | Gets a collection of DateTime objects representing the selected dates. | ||
SelectedDayStyle | Gets the style properties for the selected dates. | ||
SelectionMode | Gets or sets the selection mode that specifies whether the user can select a single day, a week or an entire month. | ||
SelectMonthText | Gets or sets the text for the month selection element in the selector column. | ||
SelectorStyle | Gets the style properties for the week and month selector column. | ||
SelectWeekText | Gets or sets the text displayed for the week selection element in the selector column. | ||
ShowDayHeader | Gets or sets the value indicating whether the heading for the days of the week is displayed. | ||
ShowGridLines | Gets or sets the value indicating whether the gridlines would be shown. | ||
ShowNextPrevMonth | Gets or sets a value indicating whether next and previous month navigation elements are shown in the title section. | ||
ShowTitle | Gets or sets a value indicating whether the title section is displayed. | ||
TitleFormat | Gets or sets the format for the title section. | ||
Titlestyle | Get the style properties of the title heading for the Calendar control. | ||
TodayDayStyle | Gets the style properties for today’s date on the Calendar control. | ||
TodaysDate | Gets or sets the value for today’s date. | ||
UseAccessibleHeader | Gets or sets a value that indicates whether to render the table header | HTML element for the day headers instead of the table data | HTML element. |
VisibleDate | Gets or sets the date that specifies the month to display. | ||
WeekendDayStyle | Gets the style properties for the weekend dates on the Calendar control. |
Calendar控件具有以下三个最重要的事件,这些事件使开发人员可以对Calendar控件进行编程。他们是:
Events | Description |
---|---|
SelectionChanged | It is raised when a day, a week or an entire month is selected. |
DayRender | It is raised when each data cell of the calendar control is rendered. |
VisibleMonthChanged | It is raised when user changes a month. |
将没有任何代码的准日历控件放置在文件后面可为网站提供可行的日历,该日历可显示一年中的月份和日期。它还允许导航到下个月和前几个月。
日历控件允许用户选择一天,一周或整个月。这是通过使用SelectionMode属性完成的。此属性具有以下值:
Properties | Description |
---|---|
Day | To select a single day. |
DayWeek | To select a single day or an entire week. |
DayWeekMonth | To select a single day, a week, or an entire month. |
None | Nothing can be selected. |
选择日期的语法:
当选择模式设置为值DayWeekMonth时,将显示带有>符号的额外列,用于选择星期,而在日期名称的左侧出现>>符号,用于选择月份。
下面的示例演示了如何选择日期并在标签中显示日期:
内容文件代码如下:
Untitled Page
事件SelectionChanged的事件处理程序:
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
lblday.Text = Calendar1.TodaysDate.ToShortDateString();
lblbday.Text = Calendar1.SelectedDate.ToShortDateString();
}
运行该文件时,应产生以下输出: