'System.StackOverflowException' when sorting a GridView

天涯浪子 提交于 2019-12-08 23:14:39

You are probably calling Sort() inside gvOutlookMeldingen_Sorting, which will call gvOutlookMeldingen_Sorting and Sort() again, thus generating a loop.

On the Sorting event you need to call functions that alter the data source and perform the query again. Or if it's automatically bound, you don't need to do anything.

Resources

Tassisto

Put your Datatable in Viewstate when you bind first time

gridView1.DataBind();
ViewState["dtbl"] = YourDataTable

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

Take a look here also on MSDN article http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorting.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!