执行数据绑定,从 ObjectDataSource 中提取行数
我有一个自定义 GridView,它自动将 SqlDataSources 中的行计数放入网格中。它计算下面代码中的计数。请注意,这个问题涉及自定义继承的 GridView 控件,而不是页面级的东西。
我如何在 PerformDataBinding 中识别“IEnumerable”事物是 ObjectDataSource?我想具体找出它是什么 ObjectDataSource 类型,然后调用它的“获取总行数”函数。
原因是总行数为(比如说)数百万,而目前 ICollection 子句返回的是从数据库中检索的内容的计数,通常是“一页”数据,因此(比如说)20记录不是20,000,000!
我只有几个特定的 ObjectDataSource 类型,因此如果我知道如何从 IEnumerable 中找到它们的名称,我就可以将它们一一挑选出来。
我回顾了这个答案: 如何获取ObjectDataSource的行数 但我不知道如何计算出我正在处理的具体 BLL。调试器在这个对象中有很多东西,但我看不到我想要的东西。
protected override void PerformDataBinding(IEnumerable data)
{
// This does not work for my Object Data Sources, which return one page of
// records only, not the whole set. There must however be a way...
if (data is IListSource)
{
IListSource list = (IListSource)data;
rowcount = list.GetList().Count;
}
else if (data is ICollection)
{
ICollection collection = (ICollection)data;
rowcount = collection.Count;
}
base.PerformDataBinding(data);
}
I have a custom GridView which automatically puts the row count from SqlDataSources into grids for me. It computes that count in the code below. Note that this question relates to the custom inherited GridView control, not page-level stuff.
How do I recognise in PerformDataBinding that the "IEnumerable" thing is an ObjectDataSource? I want to find out specifically what ObjectDataSource type it is, then call its "get total row count" function.
The reason is that the total row count is (say) millions, where as at the moment the ICollection clause returns the count of just what has been retrieved from the database, which is typically "one page" of data, so (say) 20 records not 20,000,000!
I only have a couple of specific ObjectDataSource types, so I could pick them out one by one if I knew how to find their names from this IEnumerable thing.
I have reviewed this answer:
How to get row count of ObjectDataSource
but I don't know how to work out which precise BLL I'm dealing with. The debugger has lots of stuff inside this object, but I can't see what I want there.
protected override void PerformDataBinding(IEnumerable data)
{
// This does not work for my Object Data Sources, which return one page of
// records only, not the whole set. There must however be a way...
if (data is IListSource)
{
IListSource list = (IListSource)data;
rowcount = list.GetList().Count;
}
else if (data is ICollection)
{
ICollection collection = (ICollection)data;
rowcount = collection.Count;
}
base.PerformDataBinding(data);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需枚举而不进行强制转换。
Just enumerate without casting.