On page PreRender
event store the current values of GridView.SortDirection
and GridView.SortExpression
properties in, for example, Session
:
this.Session[this.GetType().FullName + ".GridView.SortDirection"] = this.GridView.SortDirection;
this.Session[this.GetType().FullName + ".GridView.SortExpression"] = this.GridView.SortExpression;
On page Init
event execute this code:
if (!this.IsPostBack && this.Session.Contains(this.GetType.FullName + ".GridView.SortDirection"))
{
this.GridView.SortDirection = (SortDirection)this.Session[this.GetType().FullName + ".GridView.SortDirection"];
this.GridView.SortExpression = (string)this.Session[this.GetType().FullName + ".GridView.SortExpression"];
}