如何获取ObjectDataSource的行数
大家好,
我如何获取 ObjectDataSouce 的行数?
我使用 ObjectDataSource 和 DataList 。我想向用户显示一些内容,例如当 ObjectDataSource 返回某些行时在标签中。其中一种情况是没有记录时。
Thank you .Hello you all
How can i get row count of ObjectDataSouce ?
I use ObjectDataSource and DataList . I want show some thing to the user for example in a label when there are certain row returned by ObjectDataSource . One of situation is when there is no record .
Thank you .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我一直在寻找相同的答案...我最终使用的另一个解决方案如下:
该文件位于 .aspx 页面后面的 .vb 文件中。它处理数据源的“选定”事件。
I was looking for the same answer... Another solution I ended up using is the following:
This is found on a .vb file behind an .aspx page. It handles the "selected" event of the datasource.
ObjectDataSource
没有直接的方法来获取总行数。原因之一是,如果您想要的只是总行数,那么您根本不需要数据源!要获取行计数,只需与您的业务逻辑层 (BLL) 通信并获取总行数:ObjectDataSource
确实有一个SelectCountMethod
,当数据绑定控制此类时,可以使用该方法。因为 GridView 需要访问总行数。然而,这仅在执行选择操作时使用。也就是说,无法仅获取行数。行计数仅用于数据绑定控件可以显示分页器控件 - 它不用于其他任何用途。The
ObjectDataSource
does not have a direct way to get the total row count. One of the reasons for this is that if all you want is the total row count then you don't need the data source at all! To get the row count just talk to your Business Logic Layer (BLL) and get the total rows:The
ObjectDataSource
does have aSelectCountMethod
that can be used when data bound controls such as theGridView
need to access the total row count. However, this is only used while also performing a Select operation. That is, there is no way to only get the row count. The row count is only used so that the data bound control can display a pager control - it is not used for anything else.在此处找到了这个:
Found this here:
您可以使用寻呼机模板非常简单地实现此目的,例如,
这将生成文本“Results x to y of z”,包括对最后一页的检查。
干杯,
艾德
You can achieve this very simply using a pager template e.g.
This will produce the text "Results x to y of z" including a check for the last page.
Cheers,
Ed
就我而言,ObjectDatasource 是一个数据集,因此我在 objectdatasource_selected 事件中获取行号,如下所示
In my case the ObjectDatasource is a dataset, so I get row number in objectdatasource_selected event like this