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

pass datasource as a parameter

3 Answers 2052 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Francisco
Top achievements
Rank 1
Francisco asked on 09 Sep 2019, 06:15 PM
    List<ReportVentasFamiliaDto> dataSource = new List<ReportVentasFamiliaDto>();
    dataSource.Add(new ReportVentasFamiliaDto()
    {
        PorcentajeIva = 10,
        FamiliaNombre = "Familia"
    });
 
 
    var objectDataSource = new Telerik.Reporting.ObjectDataSource();
    objectDataSource.DataSource = dataSource;
    objectDataSource.DataMember = "table1";
 
    var typeReportSource = new TypeReportSource() {
        TypeName = "Report1.trdp" };
    typeReportSource.Parameters.Add(new Parameter()
    {
        Name = "objectDataSource2",
        Value = objectDataSource
    });
    typeReportSource.Parameters.Add(new Parameter()
    {
        Name = "Text",
        Value = "valor"
    });
 
 
 
    }
 
@(Html.TelerikReporting().ReportViewer()
        .Id("reportViewer1")
        .ServiceUrl(Url.Content("/api/reports/"))
        .TemplateUrl("/Resources/Templates/telerikReportViewerTemplate.html")
        .ReportSource(typeReportSource)
        .ViewMode(ViewMode.Interactive)
        .ScaleMode(ScaleMode.Specific)
        .Scale(1.0)
        .PersistSession(false)
        .PrintMode(PrintMode.AutoSelect)
)

 

 

How can I pass the datasoource as a parameter?

3 Answers, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 12 Sep 2019, 02:53 PM

Hello Francisco,

I noticed that you have a TRDP report but you are trying to use TypeReportSource which is required for CS/VB reports. Reports created with the Standalone designer (TRDP/X files) may be passed with UriReportSource.

Note that assigning the DataSource to the report or data items can be done in a  custom report resolver in the Reports Controller. You need to construct the report instance in the Resolve() method of the custom report resolver. Then the report has to be returned wrapped in an InstanceReportSource, which is the only server-side ReportSource that can take Report instance. DataSource cannot be passed through a Report Parameter.

Generally, we do not recommend report definition modifications in run time. You may set the DataSource in the report definition. Note that the data source component does not actually hold any data. It only tells the Reporting engine where to fetch the data from. For the ObjectDataSource in run time, the Reporting engine will invoke the DataMember through System.Reflection to get the data. You may customize the received data by setting parameters to the ObjectDataSource.

Regards,
Neli
Progress Telerik

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
0
Rajeev
Top achievements
Rank 1
answered on 06 Feb 2020, 10:08 PM
Hi Neli, could you provide a complete example or point to one on how to bind a List to the report. This is the problem I am running into. I have a report bound to a sqldatasource and currently running fine. However, this particular report can be run only once since last run in order to see the data changes. So after running the report if the user tries to export the data to pdf, selecting that option from the dropdown on the report toolbar, the pdf is blank since the report is being effectively run again and there are no changes since the last run (which is a few seconds ago). Does this make sense? So I need to get the data once and bind it to the report, so that the export to pdf also will bind to the same data and display the data (rather than execute the stored pro again and come out blank). Let e know if you need more info. I am also using a TypeReportSource.
0
Neli
Telerik team
answered on 11 Feb 2020, 03:09 PM

Hi Rajeev,

I suggest to open a new Support Ticket where you can attach the problematic application or just a sample project on which the behavior is reproducible. Note that it is not necessary to contain real data but it has to be runnable. Then we can investigate it further.

Regards,
Neli
Progress Telerik

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
Lauren
Top achievements
Rank 1
commented on 20 Jul 2022, 10:27 AM

Telerik.Reporting.TypeReportSource typeReportSource = new Telerik.Reporting.TypeReportSource
                                    {
                                        TypeName = typeof(OmsListingReport).AssemblyQualifiedName,
                                    };
                                    typeReportSource.Parameters.Add(new Telerik.Reporting.Parameter("id", "id"));
                                    typeReportSource.Parameters.Add(new Telerik.Reporting.Parameter("ReportModel", reportlist));

How Do I use this param to report constructor.?
Todor
Telerik team
commented on 25 Jul 2022, 08:20 AM

Hi Lauren,

As specified in the Forum thread How to pass a parameter to a report using typeResourceReport you have already followed, "It is not technically possible to pass arguments to the report constructor using a TypeReportSource. The parameter values in the TypeReportSource.Parameters collections are applied to the Report.Parameters, not the report's constructor arguments."

The parameter values from the ReportSource.Parameters collection are applied directly to the Report.Parameters collection by matching the names that are the string keys from the two Dictionaries.

The parameter values get applied early in the report processing, so you may try to access them in report events.

Tags
General Discussions
Asked by
Francisco
Top achievements
Rank 1
Answers by
Neli
Telerik team
Rajeev
Top achievements
Rank 1
Share this question
or