I have a GridView, with filtering and pagination (10 at a time), bound to a Linqdatasource. All this works.
But how can I get the Ids of all the data retrieved in the LinqDataSource after it has finished retrieval of all rows?
I have this method, and e.Result is an object data type containing List for this grid
protected void LinqDataSource_Selected(object sender, LinqDataSourceStatusEventArgs e) // event fires after data retrieval complete.
{
List<int> ids = new List<int>();
if (e.TotalRowCount > 0)
{
for (int idx = 0; idx < e.TotalRowCount; idx++)
{
Foo foo = (Foo)(e.Result[idx]); // error cannot apply indexing to expression of type object
ids.Add(foo.Id);
}
}
}
My error is iterating over an object, how can this be done?
e.Result
is anobject
, so you need to cast it to a List type to be able to apply indexing:You can either do:
Or
If your Selected is a result of a filtered view, e.Result will be an IEnumerable of anonymous type, so getting the information will most likely require using an IQueryable and a viewmodel object.