获取多页 Gridview 中的行数?

发布于 2025-01-01 09:59:44 字数 1110 浏览 2 评论 0原文

当我尝试执行以下操作时:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

牵你的手,一向走下去 2025-01-08 09:59:44

如果您正在使用 SqlDataSource 寻找此问题的答案,请使用相同的事件,但只需使用 e.AffectedRows 进行计数。

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

这对我来说非常有效。

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.

雨巷深深 2025-01-08 09:59:44
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文