Convert to list a object with anonymous type
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
精彩评论