执行数据绑定,从 ObjectDataSource 中提取行数

发布于 2024-12-09 08:53:58 字数 1123 浏览 3 评论 0原文

我有一个自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吹梦到西洲 2024-12-16 08:53:58

只需枚举而不进行强制转换。

protected override void PerformDataBinding(IEnumerable data)
        {
            var enum1 = data.GetEnumerator();
            int count = 0;
            while (enum1.MoveNext())
            {
                count++;
            }
            this.TotalRecordCount = count;

            base.PerformDataBinding(data);
        }

Just enumerate without casting.

protected override void PerformDataBinding(IEnumerable data)
        {
            var enum1 = data.GetEnumerator();
            int count = 0;
            while (enum1.MoveNext())
            {
                count++;
            }
            this.TotalRecordCount = count;

            base.PerformDataBinding(data);
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文