ObjectDataSource record count after filter

Hi,

I have a GridView bound to a ObjectDataSource - When the page loads I get 1000 records and I'm displaying this "Record Count" the user on the page.

When I apply a filter to my ObjectDataSource I get 50 records - But my "Record Count" isn't getting updated.

My code for displaying the "Record Count" is:
    Protected Sub ObjectDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Selected

        lblRecordCount.Text = "Total Records : " & DirectCast(e.ReturnValue, DataTable).Rows.Count.ToString()

    End Sub


How can I display the correct "Record Count" after I apply my filter?

Thanks, Lk
leekeyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David H.H.LeeCommented:
Hi leekey,
Probably you can try this:
Protected Sub ObjectDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Selected
 
        Dim dt as datatable
        dt= DirectCast(e.ReturnValue, DataTable)

        lblRecordCount.Text = "Total Records : " &  dt.Compute("count(ItemID)", ObjectDataSource1.FilterExpression)

    End Sub

Note: ItemID is one of the primary key from database.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leekeyAuthor Commented:
Perfect. Thankyou - Been trying to solve this one for a while.

Cheers, Lk
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.