分页 .NET 数据网格控件中所需的记录总数

发布于 2024-09-04 23:16:03 字数 308 浏览 1 评论 0原文

我正在使用数据网格并与其绑定了数据源。

我试图从 pagedDataSource DataSourceCount 重写的 InitializePager 方法中获取网格中的记录总数。

我认为 DataSourceCount 从 ObjectDataSource 的 SelectCountMethod 返回记录数,但 DataSourceCount 给我的是页面大小而不是记录总数,而当我调试并在 SelectCountMethod 中查看时,它返回正确的总记录数。

我不知道如何从 DataGrid 中的 SelectCountMethod 获取数据。

I am using a data grid and has bound a data source with it.

I am trying to get the total number of records in the grid in overriden InitializePager method from pagedDataSource DataSourceCount.

I thought DataSourceCount returns number of records from SelectCountMethod of ObjectDataSource, but DataSourceCount is giving me the page size and not the total number of records, whereas when I debug and see in SelectCountMethod it is returning correct number of total Records.

I am not sure how to get the data from SelectCountMethod in DataGrid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

音盲 2024-09-11 23:16:03

DataSource 有一个 Selected 事件,当执行 Select 和 SelectCount 方法时会触发该事件。即使它有点难看,它也是获取计数的一种方法:

protected void MyDataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
    var count = e.ReturnValue as int?;
    if (count.HasValue)
        litResults.Text = string.Format("Total results found {0}", count);
}

ObjectDataSource 的 My Count 方法返回一个 int,因此 Selected EventArgs 的 ReturnValue 是一个 int,它是计数。

希望这对您有帮助。

The DataSource has a Selected Event which is fired when the Select and the SelectCount method are executed. Even if its a bit ugly it is a way to get the count:

protected void MyDataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
    var count = e.ReturnValue as int?;
    if (count.HasValue)
        litResults.Text = string.Format("Total results found {0}", count);
}

My Count method of the ObjectDataSource returns an int, so of the ReturnValue of the Selected EventArgs is an int, its the count.

Hope this helps you.

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