Export (0) Print
Expand All
3 out of 25 rated this helpful - Rate this topic

Walkthrough: Using a Business Object Data Source with the ReportViewer Web Server Control in Local Processing Mode

This walkthrough shows how to use an object data source in a report in a Microsoft Visual Studio ASP.NET application. For more information about Business objects and object data sources, see Binding to Business Objects.

Perform the following steps to add a report to an ASP.NET Web Site Project. For this example, you will be creating the application in Microsoft Visual C#.

  1. On the File menu, point to New, and select Web Site.

  2. In the New Web Site dialog box, in the Installed Templates pane, select C#, and then choose ASP.NET Web Site. The C# node may be under Other Languages, depending on your startup settings in Visual Studio.

  3. In the Location box, specify a project directory and click OK.

    The Web site project opens.

  1. In the WebSite menu, select Add New Item.

  2. In the Add New Item dialog box, choose Class, type BusinessObjects.cs for the file name, and click Add.

  3. Click Yes to place the class in the 'App_Code' folder. The new file is added to the project and automatically opened in Visual Studio.

  4. Replace the default code for BusinessObjects.cs with the following code:

    using System;
    using System.Collections.Generic;
    
    // Define the Business Object "Product" with two public properties
    //    of simple datatypes.
    public class Product {
        private string m_name;
        private int m_price;
    
        public Product(string name, int price) {
            m_name = name;
            m_price = price;
        }
    
        public string Name {
            get {
                return m_name;
            }
        }
    
        public int Price {
            get {
                return m_price;
            }
        }
    }
    
    // Define Business Object "Merchant" that provides a 
    //    GetProducts method that returns a collection of 
    //    Product objects.
    
    public class Merchant {
        private List<Product> m_products;
    
        public Merchant() {
            m_products = new List<Product>();
            m_products.Add(new Product("Pen", 25));
            m_products.Add(new Product("Pencil", 30));
            m_products.Add(new Product("Notebook", 15));
        }
    
        public List<Product> GetProducts() {
            return m_products;
        }
    }
    
    
  5. From the Build menu, select Build Solution. This creates an assembly for the object and allows the business object Product to appear in the Report Data window after you add a report to the project.

  1. Make sure that the top-level Web site is selected in Solution Explorer.

  2. Right-click on the Web site and select Add New Item.

  3. In the Add New Item dialog, select Report Wizard. Type a name for the report and click Add.

  4. This launches the Report Wizard.

  5. In the Dataset Properties page, in the Data source box, select global.

  6. In the Available datasets box, verify that Merchant (GetProducts) is selected.

  7. Click Next.

  8. In the Arrange Fields page do the following:

    1. Drag Name from available fields to the Row groups box.

    2. Drag Price from available fields to the Values box.

  9. Click Next twice, then click Finish.

    This creates the .rdlc file and opens it in Report Designer. The tablix you created is now displayed in the design surface.

  10. Save the .rdlc file.

  1. In Solution Explorer, right-click the Web form Default.aspx and select View Designer.

  2. Open the Toolbox window. From the AJAX Extensions group, drag a ScriptManager control onto the design surface.

  3. From the Toolbox, in the Reporting group, drag the ReportViewer control onto the Web page below the ScriptManager control.

  4. Select the ReportViewer control, and open the smart tags panel by clicking the smart-tag glyph on the top right corner.

  5. In the Choose Report list, and select the report you just designed. Notice that an ObjectDataSource control appears immediately below the ReportViewer control, and is automatically set to retrieve the contents of the business object you created.

  • Press F5 to run with debugging on or CTRL + F5 to run without debugging, and view the report.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.