sterix24
sterix24

Reputation: 2400

How can I sort a gridview when using custom header text?

I've got some custom header text that's being added on the 'RowCreated' event of my gridview:

protected void gvResults_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        LinkButton lbAptNo = new LinkButton();
        lbAptNo.Text = "Apartment #";
        lbAptNo.Click += new EventHandler(lbAptNo_Click);                

        e.Row.Cells[0].Controls.Add(lbAptNo);                    
    }
}

protected void lbAptNo_Click(object sender, EventArgs e)
{            
    gvResults.Sort("aptno", SortDirection.Descending);            
}

This code works fine in the sense that it adds the link button to the gridview and allows me to sort the data in descending order. However what I'm trying to do is detect what the current sorting is for that column, and then sort asc/desc depending on what the current value is.

I understand I can use GridView.SortDirection to get the direction of a column but there's no way for me to specify which column. How do I do this? Is there a way I can determine the sort direction of a particular column?

Thanks

Upvotes: 0

Views: 1105

Answers (1)

Adil
Adil

Reputation: 148110

You can use sortexpression property of gridview to sort on column.

Upvotes: 2

Related Questions