This is a migrated thread and some comments may be shown as answers.

ReportViewer using custom reports programmatically

1 Answer 272 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Enrique
Top achievements
Rank 1
Enrique asked on 24 Nov 2016, 06:45 PM

I have been using the Report Viewer in order to create a report viewer to handle different kind of reports. I created a single report with the built-in option on Visual Studio 2015.

ReportSource rptDoc = new ReportSource();
rptDoc.IdentifierType = IdentifierType.TypeReportSource;
rptDoc.Identifier = "ReportLibrary.Sample";

 

In order to create the report. Such report does not receive any parameters, however I sill have this issue 

Unable to get report parameters.
Report 'ReportLibrary.Sample' cannot be resolved.

 

What I basically want is the following and it does not seem to have any sample or information on the whole documentation.

  • I want to use a Report and been able to set up its datasource to an objectdatasource which binds to a DataSet reading from an xml file/route.
  • Been able to set up this programmatically
  • The reportviewer must be set up on the backend side so I can enter or manipulate different reports.
  • Work on a ASP.Net web forms application.

 

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 25 Nov 2016, 12:16 PM
Hello Enrique,

The problem is relate dto the set Identifier, you must provide a type's assembly qualified name in a format like <namespace>.<report_class>, <assembly_name>.

In regards to your questions:
  1. Data-binding:
    In general, the purpose of the ObjectDataSource component is to provide data to the report in a declarative manner. The ObjectDataSource.DataSource property should be the assembly qualified name or Type of the data access layer (class), where the reporting engine will use System.Reflection to create the instance of the class (by using its default constructor) and to execute the data object's method specified by the ObjectDataSource.DataMember property.
    Already instantiated data objects do not have to be wrapped in data source components, they can be used directly as DataSource properties.
  2. Add viewer in a web application:
    You can use the HTML5 Viewer JS widget, or its WebForms wrapper. The WebForms wrapper renders the same JS object on the page. There are VS item templates for adding the viewer and the Reporting REST service e.g. How To: Use HTML5 Report Viewer in an application.
    In general:
    1. The viewer has a client-side ReportSource, from which we extract the string description of the report (relative path to a TRDP|TRDX file), the assembly qualified name of a report class (<namespace>.<report_class>, <assembly_name>) or custom string (almost anything can be included with respect to REST limitations for used characters and size of the message).
    2. The reports string description is submitted to the server and it is handled by the Reporting REST service's Resolver. The service's default resolvers can handle a relative path to a TRDP|TRDX files or an assembly qualified name of a report class. Anything else requires you to create a custom resolver that returns a server-side ReportSource object on its own.
    3. Once the Report resolver returns the server-side ReportSource object, the viewer submits the Parameters collection of its client-side ReportSource. This Parameters collection is applied as the server-side's ReportSource.Parameters collection.
    4. Next, the reporting engine starts processing the report, means the report events fire, expressions are evaluated. At that moment the server-side ReportSource.Parameters collection is mapped to the report's ReportParameters collection - where Name properties (case sensitive) are the same, values are set for the report parameters.
    5. Finally, the report is rendered and paged in the requested format (HTML for web preview, PDF for export and etc.), and the content id returned to the client(viewer).
  3. Update the displayed report:
    The HTML5 Viewer can be updated by making a postback which will recreate the page and the viewer object, or by using Javascript and the viewer's reportSource method.

  4. Modify the report at run-time:
    Data sources are not accessible directly. To modify data sources at run-time, you will have to iterate all data items to access their DataSource properties. When you use the HTML5 Viewer, this change has to be done on the server where the Reporting REST service is operating. The modifications can be done in a custom resolver used by the service. Please consider the example here.


Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Enrique
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or