Get number of records in ObjectDataSource

Posted on 2007-08-03
Last Modified: 2013-11-26
How do I determine how many records are being returned by an ObjectDataSource? The ODS in question returns a Dataview. I ask as I'd like to adjust some labels/text based on the returned record count. I don't see where the ODS exposes a records or count property.
Question by:SWRO
    LVL 24

    Accepted Solution

    You would need to put a method in your object that returns the rowcount and then put that method name in the property "SelectCountMethod" of the objectdatasource control.

    Look here for an explanation:
    LVL 37

    Expert Comment

    >>The ODS in question returns a Dataview

    you could also do something quick like:
    dim int as integer = dataview.ToTable.Rows.Count

    Author Comment

    I am binding directly to the GridView to take advantage of the built-in Paging and Sorting. According, I am not receiving the DataView as the output to my function. Rather, it is bound directly to the GV when I call myGridView.DataBind.

    I will try the SelectCountMethod avenue.

    Author Comment

    Actually, I just added a ByRef to my Method and an output PARM to my Stored Procedure. I then added a ASP:Parameter Direction=Output parameter to my ODS declaration and then called the ODS's Selected event to get the rowcount...

                        <asp:ControlParameter ControlID="ddlView" Name="View" PropertyName="Value" ConvertEmptyStringToNull="true" Type="String" />
                        <asp:Parameter Direction="Output" DefaultValue="0" Name="RowCount" Type="Int32" />
    ----ASPX.VB page
    Protected Sub odsGetProjects_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles odsGetProjects.Selected
            rowsAffected = e.OutputParameters.Item("RowCount")
            If rowsAffected > 0 Then
                If rowsAffected = 1 Then
                    Me.lblRecordsReturned.CssClass = "Message"
                    Me.lblRecordsReturned.Text = CType(rowsAffected, String) & " record found"
                    Me.lblRecordsReturned.CssClass = "Message"
                    Me.lblRecordsReturned.Text = CType(rowsAffected, String) & " records found"
                End If
            End If
        End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Visual Studio 2013 Publish 13 30
    call function 8 34
    Aspnet xml 2 27
    Sort Datagrdview programmatically 19 25
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now