DayPilot Knowledge Base

AJAX Calendar/Scheduling Controls
DayPilot Pro (AJAX Calendar Control)
» DayPilot AJAX Calendar
DayPilot Pro (AJAX Monthly Calendar Control)
» DayPilot AJAX Monthly Calendar
DayPilot Pro (AJAX Scheduler Control)
» DayPilot AJAX Scheduler
DayPilot » Knowledge Base » How to show calendar events with custom background color in DayPilot Lite [open-source]

How to show calendar events with custom background color in DayPilot Lite [open-source]

Last revision: Jun 11, 2012

asp-net-open-source-event-calendar-custom-color.png

DayPilot Lite for ASP.NET WebForms 3.1 [open-source, Apache Software License 2.0] now supports custom calendar event colors in the Calendar control.

Using BeforeEventRender event, it is possible to set custom event properties:

protected void DayPilotCalendar1_BeforeEventRender(object sender, DayPilot.Web.Ui.Events.BeforeEventRenderEventArgs e)
{
  if (e.Value == "1")
  {
    e.DurationBarColor = "red";
  }
}

You can access the source object (passed to the Calendar in the DataSource collection) using e.DataItem property:

    protected void DayPilotCalendar1_BeforeEventRender(object sender, DayPilot.Web.Ui.Events.BeforeEventRenderEventArgs e)
    {
        string color = e.DataItem["color"] as string;
        if (!String.IsNullOrEmpty(color))
        {
            e.DurationBarColor = color;
        }
    }

This way it is possible to load the event color or type directly from the database.

Related

How to show event-specific context menu
Events show HTML source during image export (PNG)
How to show business hours on weekends in Scheduler
How to set the time cell colors using database data in the Scheduler