To continue sorting after the paging is done, you will achieve this effect:
For example, a total of 15 records, each page shows 10
Then sort: The first page sorts the top 10 records, and then the second page is sorted after five.
The following points should be noted:
1. If the data is many, it is best not to put the dataset into the cache (ViewState), affect performance
2. ViewState which e.expression to store the last time and to store this e.expression is ascending or descending
Examples are as follows:
1. The existing sort event is written in this way by clicking on the above sort headers:
private void Grdprojtrace_sortcommand (object source, DataGridSortCommandEventArgs e)
{
This.grdProjTrace.CurrentPageIndex = 0;
DataView dv = Get data code;
String strsort = "";
String strorder = ";"//Sort. 0, descending, 1 ascending
if (viewstate["sortexpresstion"]!= null)
{
StrSort = viewstate[' sortexpresstion ']. ToString ();
StrSort = strsort.substring (0,strsort.length-1);
Strorder = viewstate["Sortexpresstion"]. ToString ();
Strorder = strorder.substring (strorder.length-1);
}
if (e.sortexpression = = "CustomerName")
{
if (strsort!= "CustomerName")
{
this. viewstate["sortexpresstion"] = USTOMERNAME0 ";
DV. Sort = "CustomerName DESC";
}
Else
{
if (Strorder = = "0")
{
this. viewstate["sortexpresstion"] = "CustomerName1";
DV. Sort = "CustomerName ASC";
}
Else
{
this. viewstate["sortexpresstion"] = "CUSTOMERNAME0";
DV. Sort = "CustomerName DESC";
}
}
}
if (e.sortexpression = = "FullName")
{
if (strsort!= "FullName")
{
this. viewstate["sortexpresstion"] = "FULLNAME0";
DV. Sort = "FullName DESC";
}
Else
{
if (Strorder = = "0")
{
this. viewstate["sortexpresstion"] = "fullName1";
DV. Sort = "FullName ASC";
}
Else
{
this. viewstate["sortexpresstion"] = "FULLNAME0";
DV. Sort = "FullName DESC";
}
}
}
This.grdProjTrace.DataSource = DV;
This.grdProjTrace.DataBind ();
}