DayPilot Forums

DayPilot is the best open-source Outlook-like calendar control for ASP.NET.
DayPilot Pro Demo (Calendar control)
» DayPilot Pro live demo (Calendar control)
DayPilot Pro Demo (Scheduler control)
» DayPilot Pro live demo (Scheduler control)
Home » Features » diff event background colors for certain events?

diff event background colors for certain events?

Hi,

I wanted to find out if there's a way to flag certain events to appear in one background color and others in another (for a total of 4 or 5 different background colors) based on a field off a datasource. I've downloaded the Pro Trial (and considering to purchse the Pro version if this works) and I couldn't find documentation on how to do this. Sample code to do this would be great if it's possible.

Thanks, John

Anonymous - 3/15/2007 10:47:38 PM
Yes, this is possible:

1. Specify your data source field by setting DayPilotCalendar.DataTagField. The values in this field get converted to string and are passed as Tag to BeforeEventRender event handler (see below).

2. Handle BeforeEventRender event (double-clicking on the event in Properties window in Visual Studio will create DayPilotCalendar1_BeforeEventRender).

3. Change the background color in the event handler (your special field is accessible as e.Tag):
 protected void DayPilotCalendar1_BeforeEventRender(object sender, BeforeEventRenderEventArgs e)
{
  switch (e.Tag)
  {
    case "something":
      e.BackgroundColor = "red";
      break;
    case "somethingelse":
      e.BackgroundColor = "#00ff00";
      break;
  }
}

It's also possible to change color of the column on the left side by setting e.LeftBarColor or modify the event content by setting e.InnerHTML.

I'm still working on the documentation and I hope to get it online soon.

Any other questions are welcome.
Dan Letecky - 3/15/2007 11:16:20 PM
Will the above code work in the lite version, i'm also looking to change event color backgrounds based on values pulled from the database
Jason - 6/19/2007 10:52:34 PM
Jason, this code works only in the Pro version. I recommend upgrading to Pro version but it can also be done by modifying the source code of the Lite version.
Dan Letecky - 6/20/2007 8:51:03 PM
Post reply