views:

69

answers:

1

Hi, I am a beginner to asp.net. I want to sort a gridview but the problem i m facing is when sort event handler is called the exception of stack over flow is thrown. Following is my code for sorting function.

protected void sortGridView(string strSortExpression)
{
    if (strSortExpression != string.Empty)
    {
        if (ViewState["sortOrder"] == "desc")
        {
            dgvBookInfo.Sort(strSortExpression, SortDirection.Ascending); //string.Format("{0}{1}", );
        }
        else
        {
            dgvBookInfo.Sort(strSortExpression, SortDirection.Descending);
        }
    }
}

Thanks

A: 

Hi. Add SortCommand handler and put the following code:

private void DataGrid1_SortCommand(object source, 
                       System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
   dgvBookInfo.Sort = e.SortExpression;
   DataGrid1.DataBind();
}
Teddy