获取多页 Gridview 中的行数?
当我尝试执行以下操作时:
lblTotal.text = gwGrid.rows.count()
我总是得到 50,这是我的页面的大小。我怎样才能获得返回的所有记录的计数,而不仅仅是该页面上显示的记录的计数?
我还在我的数据源上尝试了 Selected 事件:
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
但出现以下错误:
对象引用未设置到对象的实例。 在这一行: 第 85 行:Dim totalRecordCount As Integer = dt.Rows.Count
udpate:我弄清楚了:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在使用 SqlDataSource 寻找此问题的答案,请使用相同的事件,但只需使用 e.AffectedRows 进行计数。
这对我来说非常有效。
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.
That worked perfectly for me.