The key to the advanced data binding of r.a.d.
grid is handling correctly the
NeedDataSource event. That's why we chose this exact name. 'Need' in this case
actually means that if at an exact moment the data-source property does not point to a valid
data-source object, the grid will not behave correctly.
This event fires in the following cases:
- Right after OnLoad, r.a.d.grid checks the viewstate for stored grid-related
information. If such information is missing (when the page loads for the first time),
the NeedDataSource event is fired. This also means that if
MasterTableView.DataSourcePersistenceMode has been set to NoPersistence,
grid would bind each time the page loads (not only the first time)
- After automatic sorting
- When paging event occurs
- When Edit command is fired
- Right after Update/Delete/Insert command event handlers finish execution.
You can cancel these operations handling the ItemCommand event and assigning
false value to the Canceled property of the e event argument
- When grouping/ungrouping columns - right after the RadGrid.GroupsChanging event
is raised.
- When resorting a group
- When filtering column values
- When a call to the Rebind() grid method takes place
- Prior to any detail table binding
- In some other custom cases.
The advantages of using this event are that the developer does not need to write any code
handling the logic about when and how the data-binding should be processed. It is still
the developer's responsibility to construct properly a data source object and assign it to
the r.a.d.
grid's DataSource property.
In the code of the
NeedDataSource handler you should prepare the data source
(list of objects) for r.a.d.
grid and assign it to the grid's
DataSource
property.
Note: You should never call the DataBind() method from inside the
NeedDataSource handler or mix simple data-binding mode with advanced data-binding
Alternatively, you can use
AccessDataSource/SqlDataSource/ObjectDataSource/XmlDataSource controls
to populate r.a.d.
grid with data - this is another advanced data-binding mode of the control which
allows automatic operations as well. See the
Automatic operations/Editing XML using XmlDataSource control
from the
Insert/Update/Delete section of the online demos for more info.
Further information about the advanced data binding mechanism of r.a.d.
grid and the
control's lifecycle is available here:
Advanced data binding
Chapter The control lifecycle