sorting and paging with gridview asp.net
Posted
by dangerisgo
on Stack Overflow
See other posts from Stack Overflow
or by dangerisgo
Published on 2009-03-31T19:11:58Z
Indexed on
2010/04/12
12:13 UTC
Read the original article
Hit count: 572
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.
© Stack Overflow or respective owner