| |
Calendar selection changed event |
|
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Calendar</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="DayWeekMonth"
CellPadding="7"
CellSpacing="5"
DayNameFormat="FirstTwoLetters"
FirstDayOfWeek="Monday"
NextMonthText="Next >"
PrevMonthText="< Prev"
ShowGridLines="True"
DayStyle-BackColor="White"
DayStyle-ForeColor="Black"
DayStyle-Font-Names="Arial"
OnSelectionChanged="Calendar1_SelectionChanged">
<DayHeaderStyle
BackColor="Black"
Font-Names="Arial Black"
ForeColor="White" />
<SelectedDayStyle
BackColor="Cornsilk"
Font-Bold="True"
Font-Italic="True"
Font-Names="Arial"
ForeColor="Blue" />
<SelectorStyle
BackColor="Cornsilk"
Font-Names="Arial"
ForeColor="Red" />
<WeekendDayStyle
BackColor="LavenderBlush"
Font-Names="Arial"
ForeColor="Purple" />
<OtherMonthDayStyle
BackColor="LightGray"
Font-Names="Arial"
ForeColor="White" />
<TodayDayStyle
BackColor="Cornsilk"
Font-Bold="True"
Font-Names="Arial"
ForeColor="Green" />
<NextPrevStyle
BackColor="DarkGray"
Font-Names="Arial"
ForeColor="Yellow" />
<TitleStyle
BackColor="Gray"
Font-Names="Arial Black"
ForeColor="White"
HorizontalAlign="Left" />
</asp:Calendar>
<br/>
<asp:Label id="lblCount" runat="server" />
<br/>
<asp:Label id="lblTodaysDate" runat="server" />
<br/>
<asp:Label id="lblSelected" runat="server" />
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default : System.Web.UI.Page
{
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
lblTodaysDate.Text = "Today's Date is " +
Calendar1.TodaysDate.ToShortDateString();
if (Calendar1.SelectedDate != DateTime.MinValue)
lblSelected.Text = "The date selected is " +
Calendar1.SelectedDate.ToShortDateString();
lblCountUpdate();
}
private void lblCountUpdate()
{
lblCount.Text = "Count of Days Selected: " +
Calendar1.SelectedDates.Count.ToString();
}
}
|
|
|
Related examples in the same category |
|