The DataItem works only when you call .DataBind() on the Gantt control during a request. This reloads the tasks from the data source and saves the source object as e.DataItem.
If you don't call DataBind() the tasks are restored from the ViewState instead. The ViewState storage is limited to simple data objects and the source object is not stored there. In that case e.DataItem will be null.
There are two possible solutions:
1. You can store selected database fields with the tasks and make them available through the whole task lifecycle using DataTagFields:
<DayPilot:DayPilotGantt
...
DataTagFields="type, color"
/>
These fields will be loaded and the data will be stored with the event - these fields will be available on the client side:
var type = args.task.data.tag.type;
and on the server-side events (even if you don't reload the tasks):
void DayPilotGantt1_BeforeTaskRender(object sender, BeforeTaskRenderEventArgs e)
{
string type = e.Tags["type"];
// ...
}
2. You can use "Notify" event handling. In this case the Gantt chart doesn't have to be redrawn on the client side. The change is applied automatically (the row becomes selected) and then the RowSelect event is fired afterwards.
RowSelectHandling="Notify"