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

以下解决方案无效。我有一个SqlDataSource和一个GridView,它们都不能被转换为数据集或数据表。

有帮助吗?

解决方案

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

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

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

其他提示

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

如果datasource是数据表,那么

dt.Rows.Count 

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

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

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

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

其中ds是数据集对象。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top