Click here to Skip to main content
15,924,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Its Arun. This time I have a sorting issue in ASP.Net. For the first click, descending is working fine but on the second click ascending is not taken again. Its still in the descending order. I m using Tableadapter to display the gridview content. Please review the code and correct me where I ve missed.

C#
protected void gv1_Sorting(object sender, GridViewSortEventArgs e)
{
    string sdir = e.SortDirection == SortDirection.Ascending ? "DESC" : "ASC";
    DataView dv = new DataView(ds2.AllocationPending(ClientLoggedIn.Text));
    dv.Sort = e.SortExpression + " " + sdir;
    gv1.DataSource = dv;
    gv1.DataBind();
}


Also please explain - Is there any other way to apply sorting without Dataview.

Thank you.
Posted
v2

1 solution

The reason is e.SortDirection always returns Ascending....
so you need to store the e.SortDirection in a ViewState and sort the dataview with that value...
Here are some samples..
http://stackoverflow.com/questions/250037/gridview-sorting-sortdirection-always-ascending[^]


GridView Sorting[^]
 
Share this answer
 
v3
Comments
Arunachalam Gurusamy 7-May-13 7:46am    
Thank you, Its working now. I have accepted the solution.

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