开发者

Sorting a Data Gridview

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜