Wednesday, October 10, 2007

DataGrid Paging and Sorting Implementation

Unless you use ASP.NET's auto designer mode and auto features, you have to implement sorting and paging methods for the Datagrid in C# or VB.NET codes.

Declare the page index changed event and its handler in InitializeComponent() method of the C# code.
Implement the method which will set the index to the new page index.
private void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e) {
}

Do the same for sorting.


If the database query returns huge number or records, you may wanna consider Caching the recordset. Otherwise, each PageIndexChanged event will cause hitting the database again and again which results in a performance decrease.
Use the method Cache.Insert(dataset) to do this.

No comments: