Null Exception on DataItem when setting StartDate
7 years ago.
Ok, issue with this code. But using a Scheduler instead of a Calendar...
https://kb.daypilot.org/37327/how-to-show-calendar-events-with-custom-background-color-in/
protected void DayPilotScheduler1_BeforeEventRender(object sender, DayPilot.Web.Ui.Events.Scheduler.BeforeEventRenderEventArgs e)
{
string color = e.DataItem["color"] as string; // null exception here
if (!String.IsNullOrEmpty(color))
{
e.DurationBarColor = color;
}
}
The above works fine on initial rendering. However, if you have a 'previous week' and 'next week' button which sets the StartDate the above event triggers and the DataItem field is null.
// example prev week button
protected void btnPrevWeek_Click(object sender, EventArgs e)
{
DayPilotScheduler1.StartDate = DayPilotScheduler1.StartDate.AddDays(-7);
}
DayPilot