views:

517

answers:

2

The rows.count property 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.

+1  A: 

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.

rahul
+1  A: 

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.

Winterwheat