请帮助我。我用list 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源绑定到表。请帮帮我
答案 0 :(得分:0)
DataTable tbl = grduAdminSerservice.DataSource as DataTable;
您有另一种移动数据的方法,但在使用以下代码之前,您需要在绑定gridview时将数据存储在session或viewstate中:
DataSet ds =(DataSet) Session["GridData"];
DataTable dt=ds.Tables[0];