Event sequence
The API and event sequence and lifecycle of RadGrid are quite similar to MS DataGrid/GridView. The sequence of the events is as follows.
RadGrid with EnableViewState set to true (default value)
First page load
- Page.Load
- Grid_Instance.NeedDataSource
- ItemCreated for each item
- ItemDataBound for each item
- Page.PreRender
Normal postback from a control outside of RadGrid
- ItemCreated for each item
- Page.Load
- Postback Events
- Page.PreRender
On server selection from Select/Deselect GridButtonColumn/Auto Postback on row click
- ItemCreated for each item
- Page.Load
- ItemCommand
- SelectedIndexChanged
- Other postback events
- Page.PreRender
On edit/update/insert/delete action or paging/sorting/grouping/filtering operation
- ItemCreated for each item
- Page.Load
- Grid_Instance.ItemCommand
- Grid_Instance.EditCommand/UpdateCommand/InsertCommand or GridInstance.PageIndexChanged/SortCommand/GroupsChanging/ItemCommand
- Grid_Instance.NeedDataSource
- ItemCreated for each item
- ItemDataBound for each item
- Page.PreRender
Calling Rebind()
Invoking the Rebind()
method from a postback event handler of an outside control or RadGrid will raise the NeedDataSource
event. Then grid items will be recreated so the ItemCreated
and ItemDataBound
events will be raised according to the cases above.
With hierarchy
- Page_Load
- NeedDataSource
- DetailTableDataBind
After the NeedDataSource
event, the DetailTableDataBind
is raised for each detail item that will be bound. You can use the e.IsFromDetailTable
flag in NeedDataSource
to check where the call originates from, so you can fetch data only when necessary.
Which items are bound depends on the HierarchyLoadMode
property. For example, if it is set to Client
, all detail items will be bound initially on the server so they can be expanded on the client.
If you set the RetainExpandStateOnRebind
property to true
and the HierarchyLoadMode
to Client
, the NeedDataSource
and DetailTableDataBind
events will be raised first for the items that need to be expanded. These events will come before Page_Load
, whether you rebind the grid or not because the items need to be created so their Expanded
property can be set to true
.
- NeedDataSource for expanded items
- DetailTableDataBind for expanded items
- Page_Load
- NeedDataSource
- DetailTableDataBind
RadGrid with EnableViewState set to false
First page load
- Page.Load
- Grid_Instance.NeedDataSource
- ItemCreated for each Item
- ItemDataBound for each Item
- Page.PreRender
Normal postback from a control outside of RadGrid
- Page.Load
- Grid_Instance.NeedDataSource
- ItemCreated for each Item
- ItemDataBound for each Item
- Postback Events
- Page.PreRender
On server selection from Select/Deselect GridButtonColumn/Auto Postback on row click
- Page.Load
- Grid_Instance.NeedDataSource
- ItemCreated for each Item
- ItemDataBound for each Item
- ItemCommand
- SelectedIndexChanged
- Other postback events
- Page.PreRender
On edit/update/insert/delete action or paging/sorting/grouping/filtering operation
- ItemCreated for each Item
- Page.Load
- GridInstance.NeedDataSource
- ItemCreated for each Item
- ItemDataBound for each Item
- GridInstance.ItemCommand
- Grid_Instance.EditCommand/UpdateCommand/InsertCommand or GridInstance.PageIndexChanged/SortCommand/GroupsChanging/ItemCommand
- ItemCreated for each Item
- ItemDataBound for each Item
- Page.PreRender
Calling Rebind()
Invoking the Rebind()
method from a postback event handler of an outside control or RadGrid will not raise the NeedDataSource
event. Then grid items will be recreated so the ItemCreated
and ItemDataBound
events will be raised according to the cases above.
To see how to rebind the grid in this case, review the Rebind Grid with EnableViewState = false article.