开发者

Convert to list a object with anonymous type

开发者 https://www.devze.com 2022-12-14 09:48 出处:网络
I need convert to list a object with anonymous type because when i databind the gridview i get \"The data source does not supp开发者_开发百科ort server-side data paging\"

I need convert to list a object with anonymous type because when i databind the gridview i get

"The data source does not supp开发者_开发百科ort server-side data paging"

or How i can solve this?

object o =  HttpRuntime.Cache[key];

if(o is ICollection)
{
    //Sort Object
    o = ((IQueryable)this.DataSource).AsQueryable().OrderBy(SortExpresion);

    DataSource = o;

    DataBind();

}

data returned from cache are ok, the problem is that i extended the gridview control and the data type of datasource is always different, and i need sort this anonymous data stored in cache and use in the gridview


Reason is IQueryable does not support paging. You need to convert it to a more concrete type like List<T> or as REA_ANDREW suggested, PagedDataSource.

Example:

o = ((IQueryable)this.DataSource).AsQueryable().OrderBy(SortExpresion).ToList();


Set the datasource of a PagedDataSource class and then assign this object as the datasource of your gridview. Otherwise, create an object datasource and bind that to your gridview.

Andrew

0

精彩评论

暂无评论...
验证码 换一张
取 消