I want to create a report with a specific layout based on a given model, but the dataset it will be based on will be dynamically created via the (application) UI.
I'd rather do this and supply a populated model to the report than to have a report will a gazillion parameters that are populated by the app and then have the report fetch the data all over again.
Q: Can I do this?
Q: If I can can some one give me an example (Pretty Please)
Q: Can I do this using TRDX files?
Q: Can I do this using *.cs reports?
Q: Can I be really pushy and as for examples of both (Pretty Please with Sugar on).
4 Answers, 1 is accepted
Telerik Reports are templates designed based on a specific data schema. Even if data is obtained from different sources, the schema must remain the same; otherwise, the report must be created at run-time after the data is analyzed.
In case the data schema will be the same, you can build custom data access layer in a separate assembly. This data ccess layer will contain the custom logic for retrieving and caching the data to avoid consecutive calls to the data storage. The data retrieval methods can be used in a report via Object/ Entity/ OpenAccess DataSource component.
To use these data source components in the integrated in VS Report Designer, you can add a reference to the external assembly.
To use these data source components in the Standalone Report Designer, you will have to extend the tool's configuration. Details how to extend the Standalone Designer are available in Extending Report Designer and the resources linked at the bottom of the article (ConfigureStandaloneDesigner.zip contains a video illustrating the settings for extending the tool).
The usage of custom data objects allows you to save from additional data source components by applying the data-binding approaches from How to use the ReportItem.DataObject property in expressions and How to Databind to Collection Properties. (check the video in DataModelsDataBinding.zip)
In case the data schema will change (the number and name of fields will not be the same), the report will have to be created at run-time in Visual Studio. The recommended approach is to get familiar with reports structure by creating sample report with the desired layout in VS Report Designer, and re-using the code generated in the report's Designer.cs(vb) file.
An example of a Table item created at run-time based on data is available in the Displaying Dynamically Generated Columns in Report forum thread.
Let us know if you have any further questions.
I'm clearly far too stupid to use this.
I've got a report definition, which I've included below.
The report has an ObjectDataSource. You can see, from lines 144/145 that the ObjectDataSource is pointing to a model type (typeof(Genesis.UI.Reports.ViewModels.Standard.Incidents.SimpleIncidentReportVm)) and a method within the model ("Incidents")
My model looks like this ...
When the report is run I can see my model being populates with 200+ rows.
The report displays showing no data.
If I put a breakpoint on line 93 of the report definition file, when the report is run the ObjectDataSource's DataSource is null and the DataMember is "".
The breakpoint at line 144 shows the ObjectDataSource being correctly set, but for the life of me I can't see any evidence of the actual data making it to the report.
Further, my report includes a Count of the rows included that always reports zero.
I feel sure that this must be much simpler that I'm making it. I'm going to have to ask if you can explain what I'm doing wrong in terms you'd use to explain it to a pre-schooler. :-(
I've also tried explicitly setting the datasource for the table to the ObjectDataSource on the report, to no avail.
When you use an ObjectDatasource component the data source is specified by its type's name or assembly qualified name, and optionally a specififc data retrieval method. The reporting engine uses this information to create an object via Reflection, and then uses the specified data retrieval method.
For example, if we add a default constructor in which the Incidents collection is loaded, the report will load successfully the data:
If data cannot be initialized as illustrated above, you can use directly a data object instance at run-time without wrapping it in a data source as follows:
About the count of rows displayed by the Table item, you can use Data functions:
- if the count must be displayed in the PageFooterSection, you can use the PageExec data function to get the count of rows per page;
- If the count can be displayed at the end of the Table item, you can use the Exec data function with the scope of the Table item.
I hope this information helps you.