Вопрос

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