Typically RadGrid stores in ViewState only items/controls collection, not data source data. Sometimes though the page viewstate can grow too big and might significantly increase the page download time.
You can control this behavior by setting the EnableViewState property to false if you do not wish the data for the controls in the grid to to be persisted in the view state. This means that the control will need to be rebound on every request: either by firing the NeedDataSource event or by going through an ASP.NET 2.0 data source control.
When having EnableViewState set to false, RadGrid will use the page control state to store only the absolutely necessary bits of data that preserve the current paging, sorting, and grouping state.
 |
Note that disabling view state datasource storage by setting EnableViewState to false will work for the ASP.NET 2.0 build of RadGrid. The ASP.NET 1.x version of the product requires that you have view state for the control enabled. You can use the DataSourcePersistenceMode property of the GridTableView class to limit the view state size and cause a rebind on every postback much in the same way as EnableViewState does for ASP.NET 2.0. |
The DataSourcePersistenceMode property of GridTableView is an obsolete property that indicates where RadGrid will store its data and determine how the DataSource of the GridTableView will be persisted on PostBack. It has two settings:
- NoPersistence- DataSource (or generated html tables) data will not be stored. Telerik RadGrid will fire NeedDataSource event and will bind after each postback
- ViewState (default) - the grid stores data in the view-state bag. Note that this doesn't mean that Telerik RadGrid will not perform postbacks to the server. On operations like edit, sort (see the complete list) Telerik RadGrid fires NeedDataSource event and this causes the control to postback.
 |
Under ASP.NET 2.0 setting the grid MasterTableView DataSourcePersistenceMode to NoPersistence will have the same effect as disabling view state for the control (EnableViewState = false). It is recommended that you use the EnableViewState property to control this behavior. |
Some operations in Telerik RadGrid like data extraction through the ExtractValuesFromItem method, grouping, hierarchical views expand/collapse, automatic datasource operations, custom edit forms (WebUserControl and FormTemplate) or filtering require that the DataSourcePersistenceMode is set to ViewState.
If no data is persisted for items in Telerik RadGrid (NoPersistence mode or EnableViewState=false), then the state of items is lost after postback. Generally, data-source persistence optimization should be used if the small size/speed of a page, showing Telerik RadGrid, is crucial for the application. If view state optimization is enabled, RadGrid will fire NeedDataSource and will bind after each post back to restore its items.
RadGrid and its table-views manage the state of the following features while in NoPersistence mode:
- Indexes of selected items (Telerik RadGrid support this automatically only for server-side selection)
- Indexes of edited items
- Group-by expressions and settings (but not the expanded state of the grouped items)
- Sort expressions
- Style properties (but not if any style is applied on a single cell or row in ItemDataBound event)
- Columns order and other column properties
- All settings concerning hierarchy structure (but not the expanded state of the items)