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:
|
| DayStyle | The style for displaying days |
| FirstDayOfWeek | What should be the first day of week. Can take one of the following values:
|
| 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:
|
| 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:
|
| 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:
|
| 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> |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
浙公网安备 33010602011771号