We can implement it in this way without a performance impact because the data is not actually retrieved from the database until required, so we can build up a chain of queries up to that point and only the end result will be pulled from the database. When manually databinding the Grid View, this will always show ascending, so we need to handle this manually with the following logic: After that we save the new Sort Expression.
We’re sorting on the appropriate field based on the Sort Expression, and setting the direction based on Sort Direction by calling either the Order By or Order By Descending methods. As with paging, we also reset the Edit Index and Selected Index when sorting.
The required actions for paging to work are setting the new page index, setting the Data Source, and calling Data Bind (the last two through the Bind Data method).
We also want it to be something persistent, so that, for example, if you sort, then page, the sort is maintained.
The example shown here is for a Grid View, but the same types of event handlers must be implemented in roughly the same way for other data controls including the Form View, Details View, and List View. This is the final Grid View markup, so you can see the event handlers we’re going to implement.
We’ll start with binding data to the Grid View, then build up functionality from there.
The Grid View 'Grid View1' fired event Row Deleting which wasn't handled. When I say manually databinding I mean not using a data source control specified as a Data Source ID, but rather setting the Grid View’s Data Source equal to the appropriate data object and calling Data Bind. NET 2.0 are familiar with how to deal with this, but since ASP.
NET 2.0 most of the examples and tutorials deal with setting the Data Source ID, which buys you a lot of automation that you may not even appreciate unless you’ve done this the old fashioned way.
Bind Data could be called in Page Index Changing, but to show that it the event is raised, we’ve handled that in Page Index Changed.