【发布时间】:2011-05-09 07:19:32
【问题描述】:
我运行这个事件处理程序和方法来对我的 GridView 进行排序,但它说 GridView 为空:
protected void OtherGridView_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dtSortTable = gvMeldingen.DataSource as DataTable;
DataView dvSortedView = new DataView(dtSortTable);
dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);
gvMeldingen.DataSource = dvSortedView;
gvMeldingen.DataBind();
}
private string getSortDirectionString(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
if (sortDirection == SortDirection.Ascending)
{
newSortDirection = "ASC";
}
else
{
newSortDirection = "DESC";
}
return newSortDirection;
}
我得到的错误:必须在使用 DataView 之前设置 DataTable。
并突出显示:dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection)
【问题讨论】:
-
dtSortaTable 是否为空?您能否在页面的 Load 事件中发布代码?
-
我收到此错误:必须在使用 DataView 之前设置 DataTable。并突出显示:dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);
标签: c# asp.net sorting gridview