문제

I have a grid created using a sql datasource in my asp page. So Sorting is done automatically using asp.net in build control(no codes added for sorting in vb.net).

But If I refresh the page or if I go to some other page, the sorting order disappears.

Is there a way to catch the previous sort order (sort direction and sort expression)?

도움이 되었습니까?

해결책

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"];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top