2012-01-31 3 views
3

私は次の操作を実行しよう:MultiPage Gridviewで行数を取得しますか?

lblTotal.text = gwGrid.rows.count() 

は、私はいつも私のページのサイズである、50を得ます。その1ページに表示されるレコードだけでなく、返されるすべてのレコードの数を取得するにはどうすればよいですか?

は、私も自分のデータソース上で選択したイベントを試してみました:

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 

答えて

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 
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 

これは私にとってはうまくいきました。

+0

+10もしできれば!非常にシンプルで、とても働きます! – Marcel

関連する問題