【问题标题】:Manual Sorting event for GridviewGridview 的手动排序事件
【发布时间】:2010-10-29 13:47:08
【问题描述】:

请帮助我。我用列表 daatsource 创建了 gridview。我想为 gridview 应用排序事件来对所有列进行排序。

这是我的代码:

protected void grduAdminSerservice_Sorting(object sender, GridViewSortEventArgs e) {

    DataTable tbl = grduAdminSerservice.DataSource as DataTable;

    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;
}

........

但表只获得空值。如何将 gridview 源绑定到表。请帮帮我

【问题讨论】:

    标签: asp.net c#-4.0


    【解决方案1】:
    DataTable tbl = grduAdminSerservice.DataSource as DataTable; 
    

    您还有另一种移动数据的方法,但在使用以下代码之前,您需要在绑定 gridview 时将数据存储在 session 或 viewstate 中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多