Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to do when we clik on header of the column then data must be sorted i tried but i fail plese need help thanx and regards dnyaneshwar
Posted
Comments
Prince Antony G 6-Jun-12 4:37am    
did u search google engine..

try below

In design:
C#
OnSortCommand="dguser_SortCommand" AllowSorting="true"

also set SortExpression to all ur columns like below
SortExpression="FullName"


InCode Behind:
C#
public static int numberDiv;

protected void dguser_SortCommand(object source, DataGridSortCommandEventArgs e)
    {
        try
        {
            SqlDataReader dr = null;
            dr = objHRone.BindUserDetails(ddlFltStatus.SelectedValue);
            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++;
            dguser.DataSource = dv;
            dguser.DataBind();
                   }
        catch (Exception ex)
        {
            lblStatusFail.Text = ex.Message.ToString();
        }
    }
 
Share this answer
 
v2
Comments
VishalDesai 31-Dec-12 5:06am    
while clicking on next page link button the sorting order is lost. how to not loose
sorting order on going to next page.. thanku

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