我有一个GridView,过滤和分页(一次10个)绑定到Linqdatasource。所有这些工作。迭代由Linqdatasource返回的对象
但是,如何获取所有在LinqDataSource中检索到的所有数据的Ids,它已完成对所有行的检索?
我有这样的方法,并且e.Result是包含清单此网格
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);
}
}
}
我的错误是遍历一个对象的对象数据类型,这可怎么办呢?
什么样的名单呢e.Result包含哪些内容?如果e.Result是一个对象,则必须将其转换为适当的列表类型,以便应用索引 – 2012-07-17 18:37:49
,并且还缺少括号:Foo foo =(Foo)(e.Result [idx]); – 2012-07-17 18:39:29