开发者

Sorting a Data Gridview

开发者 https://www.devze.com 2022-12-23 12:21 出处:网络
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 funct

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);
        }
    }
开发者_StackOverflow}

Thanks


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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消