The Grid exposes the DataSourceNeeded event, which can be used to achieve the best performance when populating the control with large data sets.
In the event handler for this event you can manually handle the loading of the data from the database, based on the current page, page size, sort expression,
and filter expression. The second argument of this event handler is of type GridDataSourceNeededEventArgs which exposes various properties that can be used
to retrieve the necessary data from the database:

FilterExpression - gets a value indicating the current filter expression.

ForeignKeysValues - provides access to the values of all the foreign keys (this is used to populate master/detail grids).

MaximumRows - gets a value indicating the current page size.

SortExpression - gets a value indicating the current sort expression.

StartRowIndex - gets a value indicating the index of the row from the data source from where the loading should start.

TotalRowCount - sets a value indicating the total number of records from the data source (this needs to be set in the event handler).

We recommend developers to handle the sorting, paging and filtering operations in the DataSourceNeeded event handler to achieve the best performance.
Additionally, developers might decide that they don't want to do this and want to let the Grid handle these operations internally (the performance won't be the same).
To specify which operations the Grid will handle internally, use the following properties of the GridDataSourceNeededEventArgs class:

HandledFiltering - sets a value indicating whether the filtering operation was handled by the developer in the event handler.

HandledPaging - sets a value indicating whether the paging operation was handled by the developer in the event handler.

HandledSorting - sets a value indicating whether the sorting operation was handled by the developer in the event handler.

For the source code please check the "aspnet_data_sources_needed.aspx" sample from the Grid folder in the Suite.