Web Server Controls->ASP.NET Calendar Control

Definition and Usage

The Calendar control is used to display a calendar in the browser.

This control displays a one-month calendar that allows the user to select dates and move to the next and previous months.


Properties

Property Description
CellPadding The space, in pixels, between the cell walls and contents
CellSpacing The space, in pixels, between cells
DayHeaderStyle The style for displaying the names of the days
DayNameFormat The format for displaying the names of the days. Can take one of the following values:
  • FirstLetter
  • FirstTwoLetters
  • Full
  • Short
DayStyle The style for displaying days
FirstDayOfWeek What should be the first day of week. Can take one of the following values:
  • Default
  • Monday
  • Tuesday
  • Wednesday
  • Thursday
  • Friday
  • Saturday
  • Sunday
id A unique id for the control
NextMonthText The text displayed for the next month link
NextPrevFormat The format of the next and previous month links. Can take one of the following values:
  • ShortMonth
  • FullMonth
  • CustomText
NextPrevStyle The style for displaying next and previous month links
OnDayRender The name of the function to be executed when when each day cell is created
OnSelectionChanged The name of the function to be executed when the user selects a day, week, or month
OnVisibleMonthChanged The name of the function to be executed when the user navigates to a different month
OtherMonthDayStyle The style for displaying days that are not in the current month
PrevMonthText The text displayed for the previous month link
runat Specifies that the control is a server control.  Must be set to "server"
SelectedDate The selected date
SelectedDates The selected dates
SelectedDayStyle The style for selected days
SelectionMode How a user is allowed to select dates. Can take one of the following values:
  • None
  • Day
  • DayWeek
  • DayWeekMonth
SelectMonthText The text displayed for the month selection link
SelectorStyle The style for the month and weeks selection links
SelectWeekText The text displayed for the week selection link
ShowDayHeader A Boolean value that specifies whether the days of the week header should be shown
ShowGridLines A Boolean value that specifies whether the grid lines between days should be shown
ShowNextPrevMonth A Boolean value that specifies whether the next and previous month links should be shown
ShowTitle A Boolean value that specifies whether the title of the calendar should be shown
TitleFormat The format for the title of the calendar. Can take one of the following values:
  • Month
  • MonthYear
TitleStyle The style of the title of the calendar
TodayDayStyle The style for today's date
TodaysDate Today's date
VisibleDate The date that specifies the month that is currently visible in the calendar
WeekendDayStyle The style for weekends

Examples

Calendar
ASPX Source:

<html>
<body>

<form runat="server">
<asp:Calendar runat="server" />
</form>

</body>
</html>
Output Result:
< March 2007 >
Sun Mon Tue Wed Thu Fri Sat
25 26 27 28 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
1 2 3 4 5 6 7
 

In this example we declare a Calendar control in its simplest use, in an .aspx file.

Calendar 2
ASPX Source:

<html>
<body>

<form runat="server">
<asp:Calendar DayNameFormat="Full" runat="server">
   <WeekendDayStyle BackColor="#fafad2" ForeColor="#ff0000" />
   <DayHeaderStyle ForeColor="#0000ff" />
   <TodayDayStyle BackColor="#00ff00" />
</asp:Calendar>
</form>

</body>
</html>


Output Result:
< March 2007 >
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
25 26 27 28 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
1 2 3 4 5 6 7
 

In this example we declare a Calendar control in an .aspx file. The days are displayed with full names in blue, the weekends are displayed in red on a yellow background, and the current date is displayed with a green background.

Calendar 3
ASPX Source:

<html>
<body>

<form runat="server">
<asp:Calendar DayNameFormat="Full" runat="server"
SelectionMode="DayWeekMonth"
SelectMonthText="<*>"
SelectWeekText="<->"/>
   <SelectorStyle BackColor="#f5f5f5" />
</asp:Calendar>
</form>

</body>
</html>

Output Result:
< March 2007 >
<*> Sunday Monday Tuesday Wednesday Thursday Friday Saturday
<-> 25 26 27 28 1 2 3
<-> 4 5 6 7 8 9 10
<-> 11 12 13 14 15 16 17
<-> 18 19 20 21 22 23 24
<-> 25 26 27 28 29 30 31
<-> 1 2 3 4 5 6 7
 

In this example we declare a Calendar control in an .aspx file. The days are displayed with full names, the user may select a day, a week, or the whole month, and the selected day/week/month is displayed with a grey background color.


posted on 2007-03-27 08:56  改变热爱  阅读(605)  评论(0)    收藏  举报

导航