1

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

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

4

2 回答 2

3

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

如果数据源是数据表,那么

dt.Rows.Count 

将给出 dt 是数据表对象的总行数。

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

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

或者

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

其中 ds 是数据集对象。

于 2009-09-17T09:45:32.450 回答
1

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

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

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

于 2010-03-08T17:43:33.200 回答