ASP.NET Entityfraord - Grid with Pagination

Asked

Viewed 174 times

1

I am 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 paging on the grid the following error appears:

[Notsupportedexception: The data source does not support server data paging.]
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
Refeitorio.paginas.Cadusuariosaspx.carregarGrid() in C: Users sv111727 Source Redoubt Redoubt Redoubt pages Cadusuariosaspx.aspx.Cs:55 Refeitorio.paginas.Cadusuariosaspx.Page_load(Object Sender, Eventargs e) in C: Users sv111727 Source Redoubt Redoubt Redoubt 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 includedStagesBeforeAsyncPoint, Boolean includedStagesAfterAsyncPoint) +780

Does anyone know how to solve this problem?

  • tested the suggestion made in my reply?

  • A "silly" error, the author never came back to see the answer and do not believe it can be very useful to other users.

1 answer

1

The problem is in the sequence as you are running, when declaring the var lista ending with a OrderBy() you’re returning a IOrderdEnumerable<>, that does not implement the ICollection required to support paging on GridView. Pass the ToList() at the end of your declaration, so your Datasource will receive a IEnumerable<>.

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

Source: https://msdn.microsoft.com/pt-br/library/5aw1xfh3(v=vs.100). aspx

Browser other questions tagged

You are not signed in. Login or sign up in order to post.