RadGrid for ASP.NET AJAX

RadControls for ASP.NET AJAX

Typically RadGrid stores in ViewState only items/controls collection, not datasource 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 ViewState. 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.x/3.x data source control.

Note

When you set the EnableViewState property of RadGrid to False, the only supported way for binding is to use Advanced DataBinding (using NeedDataSource event or Declarative DataSources).

Although Simple DataBinding is not supported when ViewState is disabled, there is a work-around that could be used in some cases. You need to call DataBind() method on the Grid instance on Page_Load event when the Page has not been postback to the server and on Page_Init event if the Page has been postback.

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.

Some operations in Telerik RadGrid like data extraction through the ExtractValuesFromItem method, grouping, hierarchical views expand/collapse, automatic data source operations, custom edit forms (WebUserControl and FormTemplate) or filtering require that the EnableViewState is set to true. If no data is persisted for items in Telerik RadGrid (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 RadGrid, is crucial for the application. If ViewState optimization is enabled, RadGrid will fire NeedDataSource and will bind after each post back to restore its items. RadGrid and its TableView manage the state of the following features while the EnableViewState property is set to False:

  • 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)

RadGrid does NOT manage the state for the following features when its EnableViewState property is set to false:

  • Custom edit forms (user control or form template)

  • Filtering

  • Grouping

  • Expanded state of items in hierarchy

If you would like to retain the expanded state of items or server-side selection with ViewState disabled, you may consider using the approach depicted in this code library entry (applicable for explicit rebinds or ViewState switched off) or this knowledge base article . An alternative solution would be to turn on the ViewState of the grid and optimize its performance by using RadCompression and its page adapters as explained in this article.

See Also