I had some difficulties to retrieve the Total Row Count from a SqlDataSource. I used the results from the SELECT statement in the SqlDataSource to create a ListView, but got stuck to produce some code that would let me easily get the Total Row Count. I won't show all the different code i used, but show you the easy solution.
Asked
Active
Viewed 4,200 times
2 Answers
1
Assuming i have a SqlDataSource named 'dsResults' that SELECTS certain records from a DB Table. Below code retrieves the Total Row Count from that SqlDataSource through a DataView and let's you display it in a Label or use it within a CASE statement (executed at Page_Load):
Dim dssa As New DataSourceSelectArguments()
dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount)
dssa.RetrieveTotalRowCount = True
Dim dv As DataView = DirectCast(dsResults.[Select](dssa), DataView)
LabelRows.text = dv.Table.Rows.Count
Select Case dv.Table.Rows.Count
Case 0
panelResults.Visible = False
End Select

Marcellino Bommezijn
- 2,889
- 1
- 16
- 14
1
If you are binding your SqlDataSource
to a ListView
, why not simply getting the count from your ListView
instead?
LabelRows.Text = ListView1.Items.Count

Hanlet Escaño
- 17,114
- 8
- 52
- 75
-
Hanlet, I made some mistakes in code behind which let me create redundant methods to retrieve stuff. It's as easy as you mention. Thx – Marcellino Bommezijn Mar 24 '13 at 11:35