Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to sort gridview with negative and positive int values. Presently the gridview default sorting working as the negative sign was not considering.

-1
2
3
-8
-7
100

C#
private string getSortDirectionString(string Sort)
   {
       if (ViewState[Sort] == null)
       {
           ViewState[Sort] = "ASC";
       }
       else
       {
           if (ViewState[Sort].ToString() == "ASC")
           {
               ViewState[Sort] = "DESC";
               return ViewState[Sort].ToString();
           }
           if (ViewState[Sort].ToString() == "DESC")
           {
               ViewState[Sort] = "ASC";
               return ViewState[Sort].ToString();
           }
       }
       return ViewState[Sort].ToString();
   }
Posted
Comments
samit kaneriya 11-Feb-14 1:54am    
are sure your column field is not string type data type check it
FarhanShariff 5-Mar-14 5:07am    
what if the column field is string type then how to sort -ve numbers
Herman<T>.Instance 11-Feb-14 7:03am    
Where is the Gridview in your code and where do you use a table.Sort() ?

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