【问题标题】:How do I get the number of rows in my paged GridView control?如何获取分页的 GridView 控件中的行数?
【发布时间】:2009-09-17 09:39:56
【问题描述】:

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

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

【问题讨论】:

  • Count 数据源(可能是 DataTable)的属性。
  • 回发后,我将该代码放入哪个事件或方法中?
  • 您所引用的“下面的解决方案”是什么?

标签: asp.net gridview rows sqldatasource


【解决方案1】:

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

如果数据源是数据表则

dt.Rows.Count 

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

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

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

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

其中 ds 是数据集对象。

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多