How to get row count of ObjectDataSource

Mostafa picture Mostafa · Dec 13, 2009 · Viewed 21.9k times · Source

Hello you all

How can i get row count of ObjectDataSouce ?

I use ObjectDataSource and DataList . I want show some thing to the user for example in a label when there are certain row returned by ObjectDataSource . One of situation is when there is no record .

Thank you .

Answer

Watki02 picture Watki02 · Jun 23, 2011

I was looking for the same answer... Another solution I ended up using is the following: This is found on a .vb file behind an .aspx page. It handles the "selected" event of the datasource.

Protected Sub ObjectDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Selected
    ' Select data for rowcount
    Dim dt As DataTable = e.ReturnValue
    ' Set row count label
    Me.lblCount.Text = dt.Rows.Count.ToString
End Sub