?
Solved

Get number of records in ObjectDataSource

Posted on 2007-08-03
4
Medium Priority
?
1,002 Views
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.
0
Comment
Question by:SWRO
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
DBAduck - Ben Miller earned 500 total points
ID: 19626856
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:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.selectcountmethod(VS.80).aspx
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 19627350
>>The ODS in question returns a Dataview

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

Author Comment

by:SWRO
ID: 19629882
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.
0
 

Author Comment

by:SWRO
ID: 19881455
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...

---ASPX
<SelectParameters>
                    <asp:ControlParameter ControlID="ddlView" Name="View" PropertyName="Value" ConvertEmptyStringToNull="true" Type="String" />
                    <asp:Parameter Direction="Output" DefaultValue="0" Name="RowCount" Type="Int32" />
                </SelectParameters>
----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"
            Else
                Me.lblRecordsReturned.CssClass = "Message"
                Me.lblRecordsReturned.Text = CType(rowsAffected, String) & " records found"
            End If
        End If
    End Sub
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 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