Reputation: 6615
when i try to do the following:
lblTotal.text = gwGrid.rows.count()
i always get 50, which is the size of my page. how can i get the count of ALL records returned, not just the ones displayed on that one page?
i also tried the Selected event on my datasource:
Protected Sub ObjectDataSource1_Selected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
If e.Exception Is Nothing AndAlso e.ReturnValue IsNot Nothing Then
Dim dt As DataTable = TryCast(e.ReturnValue, DataTable)
Dim totalRecordCount As Integer = dt.Rows.Count
End If
End Sub
but i get the following error:
Object reference not set to an instance of an object.
on this line:
Line 85: Dim totalRecordCount As Integer = dt.Rows.Count
udpate: i figure it out:
Protected Sub ObjectDataSource1_Selected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
If e.Exception Is Nothing Then
Dim dt As DataSet = DirectCast(e.ReturnValue, DataSet)
If dt IsNot Nothing Then
lblTotal.Text = dt.Tables(0).Rows.Count.ToString()
Else
lblTotal.Text = "0"
End If
End If
End Sub
Upvotes: 3
Views: 2979
Reputation: 549
If you are looking for the answer for this question using an SqlDataSource, use the same event, but just use e.AffectedRows for your count.
Protected Sub WorkerData_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles WorkerData.Selected
If e.Exception Is Nothing Then
Dim rows As Integer = e.AffectedRows
'AddMessage(rows.ToString & " Workers selected", UpdateMessage)
End If
End Sub
That worked perfectly for me.
Upvotes: 2
Reputation: 6615
Protected Sub ObjectDataSource1_Selected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
If e.Exception Is Nothing Then
Dim dt As DataSet = DirectCast(e.ReturnValue, DataSet)
If dt IsNot Nothing Then
lblTotal.Text = dt.Tables(0).Rows.Count.ToString()
Else
lblTotal.Text = "0"
End If
End If
End Sub
Upvotes: 0