DayPilot Knowledge Base

AJAX Calendar/Scheduling Controls
DayPilot Pro (AJAX Calendar Control)
» DayPilot ASP.NET Calendar
DayPilot Pro (AJAX Monthly Calendar Control)
» DayPilot ASP.NET Monthly Calendar
DayPilot Pro (AJAX Scheduler Control)
» DayPilot ASP.NET 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

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 the selected date using a Label control
Events show HTML source during image export (PNG)
How to set the time cell colors using database data in the Scheduler
How to open a new event dialog using TimeRangeSelected event (modal.js)