3

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

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

更新:我想通了:

 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
4

2 回答 2

2

如果您正在使用 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

这对我来说非常有效。

于 2012-05-24T17:42:19.503 回答
0
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
于 2012-02-01T14:46:53.540 回答