开发者

Manual Sorting event for Gridview

Pls help me. I have created gridview with list daatsource. I want apply sorting event for gridview to sort all columns.

Here is my code:

protected void grduAdminSerservice_Sorting(object sender, GridViewSortEventArgs e) {

    DataTable tbl = grduAdminSerservice.DataSource as Da开发者_开发技巧taTable;

    if (tbl != null)
    {
        DataView dv = new DataView(tbl);
        dv.Sort = e.SortExpression + "" + getSortDirectionString(e.SortDirection);

        grduAdminSerservice.DataSource = dv;
        grduAdminSerservice.DataBind();
    }

}

private string getSortDirectionString(SortDirection sortDirection)
{
    string newSortDirection = String.Empty;
    if(sortDirection== SortDirection.Ascending)
    {
           newSortDirection = "ASC";
    }
    else
    {
           newSortDirection = "DESC";
    }

     return newSortDirection;
}

........

But table getting null value only . How can bind gridview source to table. Please help me


DataTable tbl = grduAdminSerservice.DataSource as DataTable; 

You have another way to move the data, but before you use the following code you need to store the data in session or viewstate when you bind the gridview:

 DataSet ds =(DataSet) Session["GridData"];
 DataTable dt=ds.Tables[0];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜