Skip to main content

Built-in Row Cache

  • 3 minutes to read

The Bootstrap Grid View control has a built-in cache that stores visible row data and allows the control to avoid additional data binding.

Row Cache Life Cycle

Grid View copies field values of visible and invisible columns to an internal data collection contained in a hidden field. A page sends the hidden field values to the server with postback and callback data. On the server, this data is deserialized.

When Grid View requires row data, the control attempts to load that data from the row cache. If all required rows are available in the cache, Grid View does not send a query to the database. Since the row cache contains only visible row data, this mechanism is effective exclusively if a row list on the current page does not change. For example, the row cache is particularly useful in the following scenarios when:

  • A user selects, focuses a row, or moves a column on the current page.
  • Another page control initiates a page request. In this case, Grid View data does not change unless Grid View is modified on the server side during this request.

Sort, filter, and page operations cause new rows to appear on a page. Row cache does not have data for new rows and Grid View sends a query to the database to obtain necessary data.

Methods That Can Force Data Binding

GetRowValues(Int32, String[]) | Find...TemplateControl
These methods return row values. When you call these methods, Grid View searches for a value in the row cache. If the required row data is found, data binding does not occur. Grid View binds to a data source if the row cache is disabled or has no required data.
GetRow(Int32) | GetDataRow(Int32)
These methods return a row data object rather than row values. Grid View does not store data objects in the row cache, therefore, these methods cause data binding even if the row cache contains required data.

Disable Row Cache

Set the EnableRowsCache property to false to disable the row cache. This option can be useful in the following cases:

  • Grid View displays real-time data.
  • Grid View is bound to data created at runtime. The control always reloads data from the server when you call the DataBind() method.
  • Grid View contains GridViewDataBinaryImageColumn. Since caching a binary image may take long, you can disable the row cache to speed up page loading.

How to Store Complex Objects in Cache

If you bind a grid to an XPO or custom objects that use a referenced association, the control also tries to cache references. The caching operation is similar to the ToString method. Serialization of a custom object copies data row values from a data source into an internal data collection. However, object deserialization (restoration from string to object) raises an exception:

"TypeConverter cannot convert from System.String"

You can resolve the issue in the following ways: