开发者

Number of Rows in Gridview datasource

I need to find an开发者_运维知识库d display the number of rows returned by the query. This query is made using an SQLDataSource object, which is bound to an asp.net GridView control. How can I find this information?


You can't use the Rows property on the grid, because that only gives you what the GridView is currently rendering. You need to hook up to the Selected event on the SqlDataSource and then you can pull the AffectedRows property.

protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e) {
    int totalRows = e.AffectedRows;
}


I would suggest that you handle the SQLDataSource.Selected event and check the e.AffectedRows property. It returns the number of selected rows. Also, it is possible to obtain this information programmatically:

    DataView dv = (DataView)SQLDataSource1.Select(DataSourceSelectArguments.Empty);
    int rowCount = dv.Count;

NOTE: this code will result in selecting data once again. So, the best solution is to use the Selected event for this purpose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜