DayPilot - Open-Source Outlook-Like Calendar/Scheduling Control for ASP.NET
Try the online demo: AJAX-style event creating, moving, resizing, and deleting • Context menu • Day view • Work week view • Week view • Month view • Horizontal/vertical resources view • PostBack/AJAX/JavaScript event handling • Binding to XmlDataSource, SqlDataSource, DataTable, ArrayList • Custom event formatting • UpdatePanel compatibility

4. Integration with System.Web.Ui.WebControls.Calendar

For switching the date you can use the standard .NET Framework control System.Web.UI.WebControls.Calendar. You can use the PostBack event to change the DayPilot StartDate and Days properties.

In our sample we will use the DayRender event to improve the calendar:

  • the days will become links to a specific day (i.e. no PostBack)
  • the days that contain an event will be bold
private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
	string fontWeight = "normal";
	if (isThereEvent(e.Day.Date))
		fontWeight = "bold";

	string color = "black";
	if (e.Day.IsOtherMonth)
		color = this.Calendar1.OtherMonthDayStyle.ForeColor.Name;

	e.Cell.Text = String.Format("<a href='Default.aspx?day={0:d}' style='color: "
		+ color + ";text-decoration:none; font-weight:" 
		+ fontWeight + "'>{1}</a>", e.Day.Date, e.Day.Date.Day);		
}

The method isThereEvent() returns true if a specific day contains any event. This method will be specific to your application. You can go through the data returned from the database (and supplied to DayPilotCalendar.DataSource) to avoid another database request.  We are not using the database in our sample so it is hard-coded:

private bool isThereEvent(DateTime date)
{
	DateTime today = DateTime.Now;
	DateTime tomorrow = today.AddDays(1);
	DateTime anotherDay = today.AddDays(3);

	// there are events today
	if ((date.DayOfYear == today.DayOfYear) && (date.Year == today.Year))
		return true;

	// there are events tomorrow
	if ((date.DayOfYear == tomorrow.DayOfYear) && (date.Year == tomorrow.Year))
		return true;

	// there are events on another day
	if ((date.DayOfYear == anotherDay.DayOfYear) && (date.Year == anotherDay.Year))
		return true;

	return false;
}

DayPilot Pro is an advanced DayPilot edition. You can check a thumbnail overview of the most interesting features. There is also an online demo with all the features working (including the AJAX features). If you want to test the design-time support and API you can download a fully functional trial version. And if you like it, you can buy a full version with source code and 12 months of upgrades and support (with a 30-days money back guarantee).

DayPilot Lite is a do-it-yourself open-source edition of DayPilot. Although it misses some DayPilot Pro features, there are thousands of developers using it to build calendar, personal scheduling, and resource booking applications.

Questions or suggestions? Try DayPilot forums or contact us directly.