<html>
<head>
<title>Calendar Date Selection Modes</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void Page_Load ( object src, EventArgs e ) {
myCalendar.SelectionMode = ( CalendarSelectionMode ) lstSelMode.SelectedIndex;
if ( myCalendar.SelectionMode == CalendarSelectionMode.None )
myCalendar.SelectedDates.Clear ( );
getDateSelected ( null, null );
}
void getDateSelected ( object src, EventArgs e ) {
switch ( myCalendar.SelectedDates.Count ) {
case ( 0 ) : //None
msg.Text = "No dates are currently selected";
break;
case ( 1 ) : //Day
msg.Text = "The selected date is " + myCalendar.SelectedDate.ToString ( "MMMM dd, yyyy" );
break;
case ( 7 ) : //Week
msg.Text = "The selection is a week beginning " + myCalendar.SelectedDate.ToString ( "MMMM dd, yyyy" );
break;
default: //Month
msg.Text = "The selection is a month beginning " + myCalendar.SelectedDate.ToString ( "MMMM dd, yyyy" );
break;
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Calendar Date Selection Modes</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
Choose a Selection Mode:
<asp:dropdownlist id="lstSelMode" runat="server" autopostback>
<asp:listitem value="None">None</asp:listitem>
<asp:listitem selected value="Day">Day</asp:listitem>
<asp:listitem value="DayWeek">DayWeek</asp:listitem>
<asp:listitem value="DayWeekMonth">DayWeekMonth</asp:listitem>
</asp:dropdownlist>
<p><!-- spacer --></p>
<asp:calendar id="myCalendar" runat="server"
onSelectionChanged="getDateSelected"
daynameformat="FirstLetter"
height=250 width=400
selectorstyle-backcolor="gainsboro"
todaydaystyle-backcolor="gainsboro"
dayheaderstyle-backcolor="gainsboro"
othermonthdaystyle-forecolor="gray"
titlestyle-backcolor="lightslategray"
titlestyle-font-bold
titlestyle-font-size="11pt"
selecteddaystyle-backcolor="sienna"
selecteddaystyle-font-bold
/>
<p><asp:label id="msg" runat="server" />
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>