ASP.NET EntityFraord - Grid with Paging

1

I'm building an asp.net application using entity framwork. To load the grid I use the following instructions:

        var lista = entity.Usuario.ToList().OrderBy(x=>x.nome);
        grid.DataSource = lista;
        grid.DataBind();

But when I try to configure pagination on the grid the following error is displayed:

  

[NotSupportedException: Data source does not support   paging on the server.]
  System.Web.UI.DataSourceView.RaiseUnsupportedCapabilityError (DataSourceCapabilities   capability) +2875489
  System.Web.UI.DataSourceSelectArguments.RaiseUnsupportedCapabilitiesError (DataSourceView   view) +62
  System.Web.UI.WebControls.ReadOnlyDataSourceView.ExecuteSelect (DataSourceSelectArguments   arguments) +17
  System.Web.UI.DataSourceView.Select (DataSourceSelectArguments   arguments, DataSourceViewSelectCallback callback) +22
  System.Web.UI.WebControls.GridView.CreateChildControls (IEnumerable   dataSource, Boolean dataBinding) +367
  System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding (IEnumerable   date) +67
  System.Web.UI.WebControls.GridView.PerformDataBinding (IEnumerable   date) +14
  System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback (IEnumerable   date) +128
  System.Web.UI.DataSourceView.Select (DataSourceSelectArguments   arguments, DataSourceViewSelectCallback callback) +34
  System.Web.UI.WebControls.DataBoundControl.PerformSelect () +143
  System.Web.UI.WebControls.BaseDataBoundControl.DataBind () +74
  System.Web.UI.WebControls.GridView.DataBind () +9
  Download.Page.CadUsers.Page.Grid () in   C: \ Users \ sv111727 \ Source \ Directory \ Directory \ Directory \ Directory \ Pages \ CadUsuariosaspx.aspx.cs: 55   Path.Page.Page_Load (Object sender, EventArgs   e) in   C: \ Users \ sv111727 \ Source \ Directory \ Directory \ Directory \ Directory \ Pages \ CadUsuariosaspx.aspx.cs: 16   System.Web.Util.CalliEventHandlerDelegateProxy.Callback (Object sender,   EventArgs e) +51 System.Web.UI.Control.OnLoad (EventArgs e) +95
  System.Web.UI.Control.LoadRecursive () +59
  System.Web.UI.Page.ProcessRequestMain (Boolean   includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)   +780

Does anyone know how to solve this problem?

    
asked by anonymous 09.05.2018 / 17:07

1 answer

1

The problem is in the sequence you are executing, when declaring var lista ending with OrderBy() you are returning IOrderdEnumerable<> , which does not implement the ICollection required for paging support in GridView . Pass ToList() to the end of your declaration, so your DataSource would receive a IEnumerable<> .

var lista = entity.Usuario.OrderBy(x=>x.nome).ToList();
grid.DataSource = lista;
grid.DataBind();

Source: link

    
09.05.2018 / 17:37