Search code examples
c#objectdatasourcerowcount

How to get row count of ObjectDataSource


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 .


Solution

  • 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