Working with FlexReport / Data Binding in FlexReport / Data Binding using External Objects
Data Binding using External Objects

You can easily use external objects for data binding in FlexReport. Here, we discuss data binding using Open Data Protocol (OData) client library. The OData allows you to access data in the same style as in Representational State Transfer (REST) resources. The use of Simple.OData.Client library for data binding is illustrated below.

Create a Report Definition

Create a report definition using code to bind the data using OData client library.

  1. Add the following namespace in code view:
    using Simple.OData.Client;
  2. Create an object of FlexReport using the following code:
    Dim _report As New C1FlexReport()
    
  3. Add following code to request data from OData service:
    ' request data from OData service
    Dim client = New ODataClient(ODataUri)
    ' select all categries and products of each category
    Dim categories = (Await client.[For](Of Category)().Expand(Function(x) New From { _
            x.Products _
    }).FindEntriesAsync()).ToList()
    Dim products = (From c In categoriesFrom p In c.ProductsNew With { _
            Key .CategoryID = c.ID, _
            Key .CategoryName = c.Name, _
            Key .ID = p.ID, _
            Key .Name = p.Name, _
            Key .Description = p.Description, _
            Key .ReleaseDate = p.ReleaseDate, _
            Key .DiscontinuedDate = p.DiscontinuedDate, _
            Key .Rating = p.Rating, _
            Key .Price = p.Price _
    }).ToList()
    
  4. Add a new folder named Resources to your application and add a report to it. In our case, we are using Reports.flxr report.
  5. Load the report definition from Resources folder using the following code:
    ' load report definition from resources
    Dim asm As Assembly = GetType(MainPage).GetTypeInfo().Assembly
    Using stream As Stream = asm.GetManifestResourceStream("Binding.Resources.Reports.flxr")
            _report.Load(stream, "Products")
    End Using
    
    ' assign dataset to the report
    _report.DataSource.Recordset = products
    
  6. Use the following code to build your report and view it in FlexViewer control after loading the report definition:
    Try
            ' build report
            prMain.IsActive = True
            Await BuildProductsReport()
            prMain.IsActive = False
    
            ' assign report to the preview pane
            flxViewer.DocumentSource = Nothing
            flxViewer.DocumentSource = _report
    Catch ex As Exception
            Dim md As New MessageDialog(String.Format("Failed to show ""{0}"" report, error:" & vbCr & vbLf & "{1}", reportName, ex.Message))
            Await md.ShowAsync()
    End Try
    

The report appears similar to the following: