如何获得ObjectDataSource控件的行数 [英] How to get row count of ObjectDataSource
问题描述
我怎样才能ObjectDataSouce的行数?
How can i get row count of ObjectDataSouce ?
我用ObjectDataSource控件和DataList控件。我想显示一些东西给用户,例如在一个标签时存在由ObjectDataSource返回某些行。一种情况是当没有记录。
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 .
推荐答案
的 ObjectDataSource控件
没有直接的方式来获得总行数。其中一个原因是,如果你想要的是总的行数,那么你就不需要数据源了!要获取行计数只是跟你的业务逻辑层(BLL),并获得总行:
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:
MyBLL bll = new MyBLL();
int customerRowCount = bll.Customers.GetRowCount();
的
ObjectDataSource控件
的确有 SelectCountMethod
时,数据绑定,如 GridView控件
控制,可用于需要访问总行数。然而,同时还执行选择操作这只使用。也就是说,没有办法的只有的获取行计数。该行数仅用于使绑定控件可以显示导航控件中的数据 - 它不能用于别的
The ObjectDataSource
does have a SelectCountMethod
that can be used when data bound controls such as the GridView
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.
这篇关于如何获得ObjectDataSource控件的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!