Binding Data to the ReportViewer Control Dynamically in ASP.NET 2.0 - Binding a customized ObjectDataSource (or business logic) to a ReportViewer control in ASP.NET 2.0: code
(Page 6 of 6 )
This is an extension from the previous section. Add one more class (Sales.vb), which is mainly used to expose the objects based on the above class. The code should look like the following:
ImportsMicrosoft.VisualBasic
ImportsSystem.Data
ImportsSystem.Collections.Generic
PublicClass Sales
Public Function ListSales() As ArrayList
Dim Sales As New ArrayList
Dim fileName As String =
HttpContext.Current.Request.MapPath("SalesData.csv")
Using parser As New FileIO.TextFieldParser(fileName)
parser.Delimiters = New String() {","}
parser.HasFieldsEnclosedInQuotes = False
Dim fields As String()
fields = parser.ReadFields()
Do While fields IsNot Nothing
Dim info As New SalesInfo
With info
.SalesPersonID = fields(0)
.FirstName = fields(1)
.SalesQuota = fields(2)
.SalesYTD = fields(3)
.SalesLastYear = fields(4)
End With
Sales.Add(info)
fields = parser.ReadFields()
Loop
End Using
Return Sales
End Function
EndClass
Now, add a new web form (ObjectBasedReport.aspx), drag a ReportViewer control and finally set “SampleReport.rdlc” at the “Choose Report” option in the Smart Tag.

That automatically adds an “ObjectDataSource” control to your designer.
Using the “ObjectDataSource,” open the smart tag menu and choose “Configure Data Source.”

You will be provided with a wizard. Provide “Sales” as your “business object” and click "Next."

In the next screen, for the SELECT tab, choose “ListSales(), returns ArrayList” as the method.

For all the rest of the tabs, you can select “none.” Finally click “Finish.” When you execute, your reports get bound to the customized business logic object source!
Any feedback, problems, suggestions, bugs, errors, improvements etc., are highly appreciated at http://jagchat.spaces.live.com.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |