sorting and paging with gridview asp.net
- by dangerisgo
I'm trying to get a gridview to sort and page manually with no success.
The problem is that when a user clicks the column they want to sort, it sorts that page, but doesn't sort the datasource (dataview) behind the gridview. So when they progress to a different page, their sort is lost. Pretty much I'm looking for a sort that will actually sort the datasource behind the gridview. Here is what I have so far:
protected void GridView_OnSort(object sender, GridViewSortEventArgs e)
{
String sortExpression = e.SortExpression;
if (GridViewSortDirection == SortDirection.Ascending)
{
DataView myDataView = new DataView(mybll.GetItemsOrdered());
myDataView.Sort = sortExpression + " DESC";
GridView.DataSource = myDataView;
GridView.DataBind();
}
else
{
DataView myDataView = new DataView(mybll.GetItemsOrdered());
myDataView.Sort = sortExpression + " ASC";
GridView.DataSource = myDataView;
GridView.DataBind();
}
}
Any help would be appreciated. Thanks.