Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used SortExpression in all of my columns in Grid View. When I Sort any of the column and than do edit of the column ,the page gets Postback(It needs to be postback in my case)and It displays me the old value selected for editing, before Sorting. Sorting is not maintained after PostBack. I think that to maintain Sorting after Postback will be helpful but I am not getting it.
Please help me how to do that or if you have any new way to do.
Posted

1 solution

You have to store the sortexpression locally such that whenever there is postback you can re-apply the same.

Try:
C#
public string SortExpression {
    get {
        if (ViewState("SortExpression") == null) {
            ViewState("SortExpression") = "LastName ASC";
        }
        return ViewState("SortExpression").ToString;
    }
    set { ViewState("SortExpression") = value; }
}

Apply this SortExpression every time you load/populate your gridview.
 
Share this answer
 
Comments
VJ Reddy 4-May-12 9:36am    
Good answer. 5!
Sandeep Mewara 4-May-12 9:59am    
Thanks VJ.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900