a) Display messages in a calendar control
b) Display vacation in a calendar control
c) Selected day in a calendar control using style
d) Difference between two calendar dates
Program:
b) Display vacation in a calendar control
c) Selected day in a calendar control using style
d) Difference between two calendar dates
Program:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="Practical_3b._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1"
runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
ShowGridLines="True" Width="220px"
ondayrender="Calendar1_DayRender" onselectionchanged="Page_Load">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
</asp:Calendar>
<asp:Label ID="Label1" runat="server"></asp:Label> <br />
<asp:Label ID="Label2" runat="server"></asp:Label> <br />
<asp:Label ID="Label3" runat="server"></asp:Label> <br />
<asp:Label ID="Label4" runat="server"></asp:Label> <br />
<asp:Label ID="Label5" runat="server"></asp:Label> <br />
<asp:Button ID="Result" runat="server" onclick="Result_Click" Text="Result" />
<asp:Button ID="Reset" runat="server" onclick="Reset_Click" Text="Reset" />
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Practical_3b
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text
= "Your Selected Date:" +
Calendar1.SelectedDate.Date.ToString();
}
protected void Result_Click(object sender, EventArgs e)
{
Calendar1.Caption
= "Calendar Control";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
Label2.Text = "Todays Date"
+ Calendar1.TodaysDate.ToShortDateString(); Label3.Text = "Ganpati Vacation Start : 09-13-2018";
TimeSpan d = new DateTime(2018, 09, 13) - DateTime.Now;
Label4.Text
= "Days Remaining For Ganpati Vacation:"
+ d.Days.ToString();
TimeSpan d1 = new DateTime(2018, 12, 31) - DateTime.Now;
Label5.Text
= "Days Remaining for New Year:" +
d1.Days.ToString();
if (Calendar1.SelectedDate.ToShortDateString()
== "9-13-2018")
Label3.Text
= "<b>Ganpati Festival Start</b>";
Label3.Text
= "<b>Ganpati Festival End</b>";
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date.Day == 5 && e.Day.Date.Month == 9)
{
e.Cell.BackColor = System.Drawing.Color.Yellow; Label lbl = new Label();
lbl.Text = "<br>Teachers Day!";
e.Cell.Controls.Add(lbl);
Image g1 = new Image();
g1.ImageUrl
= "TEACHER.jpg";
g1.Height
= 20;
g1.Width =
20;
e.Cell.Controls.Add(g1);
}
if (e.Day.Date.Day == 13 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2018, 9, 12); Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,
Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text
= "<br>Ganpati!";
e.Cell.Controls.Add(lbl1);
}
}
protected void Reset_Click(object sender, EventArgs e)
{
Label1.Text
= "";
Label2.Text
= "";
Label3.Text
= "";
Label4.Text
= "";
Label5.Text
= "";
Calendar1.SelectedDates.Clear();
}
}
}
Comments
Post a Comment