1

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.

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 に答える