<%@PageLanguage="C#"AutoEventWireup="true" CodeFile="Default.aspx.cs"Inherits="_Default"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""

htmlxmlns="

headrunat="server">

titlePete's Pizza Home</title

</head

body

formid="form1"runat="server">

div

h1Pete's Pizza</h1

asp:CalendarID="Calendar1"runat="server"BackColor="White"BorderColor="White"

BorderWidth="1px"Font-Names="Verdana"Font-Size="9pt"ForeColor="Black"

Height="190px"NextPrevFormat="FullMonth"ondayrender="Calendar1_DayRender"

Width="350px">

SelectedDayStyleBackColor="#333399"ForeColor="White"/>

TodayDayStyleBackColor="#CCCCCC"/>

OtherMonthDayStyleForeColor="#999999"/>

NextPrevStyleFont-Bold="True"Font-Size="8pt"ForeColor="#333333"

VerticalAlign="Bottom"/>

DayHeaderStyleFont-Bold="True"Font-Size="8pt"/>

TitleStyleBackColor="White"BorderColor="Black"BorderWidth="4px"

Font-Bold="True"Font-Size="12pt"ForeColor="#333399"/>

</asp:Calendar

</div

</form

</body

</html

using System;

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;

using System.Data.SqlClient; //This library contains sql server

//data controls

publicpartialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender, EventArgs e)

{

}

//This method runs as the calendar is being drawn for the browser

//that allows for you to change the way the number for the day is shown

protectedvoid Calendar1_DayRender(object sender, DayRenderEventArgs e)

{

//The SqlConnection object connects to the database. You must

//provide it a string that tells what server and what database to use

// and what kind of connection. There are several other parameters

//available also. Integrated security means using window’s login.

//If you are using IIS you must map a windows login to SQL Server

//and to the database—aspnet in XP, IUser in Vista

SqlConnection connect = newSqlConnection("Data Source=.\\sqlExpress;Initial catalog=PetesPizza;integrated Security=true");

//command objects contain SQL (and other commands) needed

//to retrieve data from the database (or write data to it)

SqlCommand cmd = newSqlCommand("Select EventName, EventDate from Event", connect); //Create the command, give it the sql string and tell it what connection to use

DataSet ds = newDataSet(); //Datasets store data

//the data is stored as tables. Each DataSet can store multiple tables

//the SqlAdapter is a portal or a valve that passes commands from the application

//to the database and that passes the data that is returned into a DataSet

SqlDataAdapter da = newSqlDataAdapter(cmd);

//This is the line that actuall does the work. It opens the connection,

//passes the command to the database, gets the data from the database,

//and writes it into the table “dsEvent” within the DataSet

da.Fill(ds, "dsEvent");

//We are creating a new style in code;

Style eventStyle = newStyle();

eventStyle.ForeColor = System.Drawing.Color.Red;

//A DataSet contains tables. Tables Contain rows. Rows Contain

//Columns. In this loop we loop through all the rows in our table

//dsEvent and see if the dates match any of the days being rendered

//in the calendar. Before we do that we need to cast the column

//in the row to the data type DateTime and then convert it a string with

//the format shortDateString. We do this inorder that the calendar date

//and the date from the database match exactly. Otherwise we

//can’t compare them

foreach (DataRow row in ds.Tables["dsEvent"].Rows)

{

//Create a variable “d” and assign it the value of the column

//EventDate cast to a DateTime Data Type

DateTime d =(DateTime)row["EventDate"];

//create a string variable “dt” and convert d to string

string dt = d.ToShortDateString();

//Now compare the two. If they match apply the style

//e comes from the arguments to the method “DayRenderEventArgs e”

if(dt==e.Day.Date.ToShortDateString())

{

e.Cell.ApplyStyle(eventStyle);

}

}

}

}