search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Gantt: Property task.DataItem null after RowSelect

Asked by Anonymous
4 years ago.

Hello,

on PageLoad I filled atask list of a Gantt, including storing some data (used for formatting in BeforeTaskRender) in DataItem.
After a RowSelect (RowClickHandling is set to Select) the Task items seems to be redrawn, each with event BeforeTaskRender. But at this time the DataItem objekt is null. So I do not have the information I need there for formatting e.Box.Html for example.
Why is that information not available after RowSelect?
If I reload all Task after a RowSelect I will loose all information on before expanded and collepsed items, so that is not a solution.

Can you assist?

Best regards

Answer posted by Dan Letecky [DayPilot]
4 years ago.

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"
This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.