Click here to Skip to main content
15,908,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i want to show the ascending and decending order in a grid by click the header column..

send me the code
Posted

You have a property called AllowSorting="true" for gridviw. Then you have to use SortExpression="columnname" in columns(BoundField). Check the below links.

http://msdn.microsoft.com/en-us/library/aa479347.aspx[^]

http://asp-net-example.blogspot.com/2008/12/aspnet-gridview-sorting-example-how-to.html[^]
 
Share this answer
 
v4
 
Share this answer
 
v2
Comments
skkworld 13-Oct-11 3:37am    
thx permalink. work this coding http://www.highoncoding.com/ArticleDetails.aspx?articleID=176[^]
OnSortCommand="datagrid1_SortCommand" AllowSorting="true" and set SortExpression="ColumnName" for which column you want sort




C#
public static int numberDiv;
protected void datagrid1_SortCommand(object source, DataGridSortCommandEventArgs e)
    {
        
            SqlDataReader dr = null;
            dr = objSource.GetList();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            dt.Load(dr);
            DataView dv = new DataView(dt);

            if ((numberDiv % 2) == 0)
                dv.Sort = e.SortExpression + " " + "ASC";
            else
                dv.Sort = e.SortExpression + " " + "DESC";
            numberDiv++;
            datagrid1.DataSource = dv;
            datagrid1.DataBind();
           
        
    }
 
Share this answer
 
v3
use this property

AllowSorting="true" for gridviw & then SortExpression="your columnname" in columns(BoundField)
 
Share this answer
 
v2

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