排序GridView时出现'System.StackOverflowException' [英] 'System.StackOverflowException' when sorting a GridView
问题描述
当我尝试对GridView进行排序时,系统会返回以下错误消息:
When I try to sort a GridView, the system returns this error-message:
gridview sort类型为$ b的未处理异常$ b'System.StackOverflowException'发生在System.Web.dll中
gridview sort An unhandled exception of type 'System.StackOverflowException' occurred in System.Web.dll
这是代码,Melder是列进行排序。
This is the code and "Melder" is the name of the column to sort.
gvOutlookMeldingen.Sort("Melder", SortDirection.Ascending);
推荐答案
第一次绑定数据表时, / p>
Put your Datatable in Viewstate when you bind first time
gridView1.DataBind();
ViewState["dtbl"] = YourDataTable
然后就像... p>
and then do like...
protected void ComponentGridView_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = ViewState["dtbl"] as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirection(e.SortDirection);
ComponentGridView.DataSource = dataView;
ComponentGridView.DataBind();
}
}
private string ConvertSortDirection(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}
请在这里查看MSDN文章 http://msdn.microsoft.com/zh-cn/library/system .web.ui.webcontrols.gridview.sorting.aspx
Take a look here also on MSDN article http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorting.aspx
这篇关于排序GridView时出现'System.StackOverflowException'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!