Progress® Telerik® Reporting R3 2021

New to Telerik Reporting? Download free 30-day trial

ObjectDataSource Wizard

The Object Data Source Wizard allows you to create a new or edit an existing ObjectDataSource component in the Telerik Web Report Designer. This article describes how to create a project with business objects and how to add them by using the Object Data Source Wizard that you can invoke from the Report Designer toolbox with components.

Creating the DataSource

The purpose of the ObjectDataSource component is to provide business objects data to data items in a declarative manner. For that reason, firstly, you need to create a project with the datasource. Note that it is highly recommended extracting the business objects into a separate project. By doing this, you will be able to use the class in the Standalone designer by just copying the assembly in the designer folder and registering it in the designer config file. In order to select the right type of .NET implementation and version, you can use the .NET Standard compatibility chart which explains how and when the assemblies can be loaded in different framework versions.

In this example, we will use a .NET Standard 2.0 Class Library which is suitable for both .NET Framework and .NET Core applications. It will contain the business objects which in this case will be cars. Below you can see all required steps for building the project.

  1. Open Visual Studio and create a new .NET Standard 2.0 Class Library. Name the project CarObjects.

  2. Add a new class named Car which will contain the model of the car.

    C#
    public class Car
     {
         string manufacturer;
         string model;
         int year;
         string imageUrl;
         ArrayList availableColor;
    
         public Car(string manufacturer, string model, int year, string imageUrl, string[] availableColor)
         {
             this.manufacturer = manufacturer;
             this.model = model;
             this.year = year;
             this.imageUrl = imageUrl;
             this.AvailableColor = new ArrayList(availableColor);
         }
    
         public string Model
         {
             get { return this.model; }
             set { this.model = value; }
         }
    
         public string Manufacturer
         {
             get { return this.manufacturer; }
             set { this.manufacturer = value; }
         }
    
         public int Year
         {
             get { return this.year; }
             set { this.year = value; }
         }
    
         public string ImageUrl
         {
             get { return this.imageUrl; }
             set { this.imageUrl = value; }
         }
    
         public ArrayList AvailableColor
         {
             get { return this.availableColor; }
             set { this.availableColor = value; }
         }
    
     }
  3. Add another class named Cars. It will contain a list with cars.

    C#
    public class Cars : List<Car>
      {
          public Cars()
          {
              Car car;
              car = new Car("Honda", "NSX GT", 2003, "http://www.telerik.com/images/reporting/cars/NSXGT_7.jpg"
                  , new string[] { "Black", "Red", "White", "Orange" });
              this.Add(car);
    
              car = new Car("Nissan", "Skyline R34 GT-R", 2005, "http://www.telerik.com/images/reporting/cars/EVLR34_1.jpg"
                  , new string[] { "Black", "White" });
              this.Add(car);
    
              ...
          }
      }

  4. Build the project.

Now you have the project with data. The next step is to make the configurations in the project with the Web Report Designer.

Configuring the DataSource in the WebReportDesigner

When started, the application that hosts the Web Report Designer will try to resolve the registered assemblies in the configuration folder of the project. Resolving them means that the .NET runtime will try to load the assemblies into the application domain. For example the \bin\Debug\ folder.

  1. You need to add the assembly as a reference to the project or copy it through a post-build action to the output directory of the application. Note that if the assembly depends on other assemblies, you will also have to add the dependent assemblies to the working folder.

  2. In order to use the custom assembly for ObjectDataSource, it needs to be registered in the application's configuration file.

    • For .NET Core applications, this is done in the appsettings.json file:

      JavaScript
      "telerikReporting": {
          "assemblyReferences": [
             {
               "name": "CarObjects"
             }
           ]
          }

      Another option is by custom implementation of the IConfiguration interface.

    • For .NET Framework projects, the configuration should be added to the web.config file.

      <configuration> 
        <configSections>
          <section name="Telerik.Reporting"
                   type="Telerik.Reporting.Configuration.ReportingConfigurationSection, Telerik.Reporting"
                   allowLocation="true" 
                   allowDefinition="Everywhere" />
        </configSections>
        <Telerik.Reporting>
          <AssemblyReferences>
            <add name="CarObjects"/>
          </AssemblyReferences>
        </Telerik.Reporting>
      </configuration>

We are ready with the configuration. Now let's step to the wizard.

Adding the ObjectDataSource through the Wizard

Once you have registered the assembly, run the Web Report Designer project. Go to the Components tab and click on Object Data Source. Follow the steps below to complete Wizard.

  1. Choose a business object

    The selected business object type's assembly-qualified name will be stored in the data source component's DataSource property.

    In this screen, expand CarObjects and select Cars. Click on Next.

  2. Choose a data member

    The business object instance will be created using its default constructor. You have the option to specify a different constructor or a data member (method or property) that will return the data.

    Here, you need to keep the default option- Use the default constructor. Click on Next.

  3. Configure data source parameters

    In this step, you can specify default value or expression and design-time value for data source parameters.

    In this scenario, this step will be skipped because the selected default constructor does not have any parameters.

  4. Preview data source results

    During data preview the business object will be called using the configured design-time parameter values if such are specified.

    This is the last step of the wizard. After pressing Finish the wizard will configure the ObjectDataSource component with the specified settings and close.

Displaying the Data

As a final step, let's display the data from the ObjectDataSource in the report.

  1. From the Explorer tab, click on the Report.

  2. Then, from the Properties pane, go to Data -> DataSource and select the ObjectDataSource.

  3. Drag the fields from the Explorer tab to the report and hit Preview.

See Also

In this article
Not finding the help you need?