如何获取分页 GridView 控件中的行数?

发布于 2024-08-05 04:40:37 字数 126 浏览 3 评论 0原文

GridView 控件上的 rows.count 属性仅告诉我屏幕上显示的行数,而不是可用的总数。

下面的解决方案不起作用。我有一个 SqlDataSource 和一个 GridView,但两者都不能转换为数据集或数据表。

The rows.count property on my GridView control only tells me how many rows are displayed on the screen, not the total number available.

The solution below is not working. I have an SqlDataSource and a GridView and neither can be cast into a dataset or datatable.

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

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

发布评论

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

评论(2

风筝有风,海豚有海 2024-08-12 04:40:37

我认为您需要获取数据源的行数。

如果数据源是数据表,

dt.Rows.Count 

则将给出总行数,其中 dt 是数据表对象。

如果是数据集则获取对应的数据表,然后获取行数。

ds.Tables["tablename"].Rows.Count;  // give the datatable name

或者

ds.Tables[tableIndex].Rows.Count;  // give the datatable index

其中 ds 是数据集对象。

I think you need to get the rows count of the datasource.

If datasource is datatable then

dt.Rows.Count 

will give the total number of rows where dt is the datatable object.

If it is a dataset then get the corresponding datatable and then take the rows count.

ds.Tables["tablename"].Rows.Count;  // give the datatable name

or

ds.Tables[tableIndex].Rows.Count;  // give the datatable index

where ds is the dataset object.

烂柯人 2024-08-12 04:40:37

SqlDataSource 有一个名为 OnSelected 的事件,您可以将其设置为如下所示的方法 -

protected void OnSelectedData(object sender, SqlDataSourceStatusEventArgs e)  
{  
    // Set the record count label  
    RecordCountLabel.Text = "Total Records: " + e.AffectedRows;  
}  

请注意,e.AffectedRows 包含所选行的总数。

The SqlDataSource has an event called OnSelected that you can set to a method like the one below -

protected void OnSelectedData(object sender, SqlDataSourceStatusEventArgs e)  
{  
    // Set the record count label  
    RecordCountLabel.Text = "Total Records: " + e.AffectedRows;  
}  

Notice that the e.AffectedRows contains the total number of rows selected.

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