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

Report Book, Report Instances and Parameters

7 Answers 536 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 10 Oct 2014, 04:33 PM
Hi there,

After having some issues figuring out how to get multiple reports in a single document, I finally stumbled onto the ReportBook class. 

I have implemented a number of different single page report documents and have, up until now, had no trouble adding them to the book and getting them to display. The issue that I've come across is that I have one derivation of the report that requires three separate instances of a single page, so

public class MultiSheetReport_Group1 : Telerik.Reporting.ReportBook
{
    public MultiSheetReport()
    {
        this.Reports.Add(new CoverPages.GroupOneCoverPage());
        this.Reports.Add(new ItemizedPages.GroupOneItems());
    }
}

now, I have an Group that requires a monthly breakout of the itemized page, so there is a GroupFourItems report that takes in both the id to read as well as the month value that I would like to print that report for.  The issue that I am having is that for each instance of the Monthly Report, the same value is being sent to the ObjectDataSource constructor for the month value.

I've attempted to create another constructor for the MultiSheetReport() like so:

public MultSheetReport(int parentId)
{
    var monthTriplet = DateTimeHelper.GetMonthOrdinals(parentId);
    // monthTriplet is a Tuple of int, int, int
    var cvrPage = new CoverPages.GroupOneCoverPage();
    cvrPage.ReportParameters.Clear();
    cvrPage.ReportParameters.Add(new ReportParameter("id", ReportParameterType.Integer, parentId));
    this.Reports.Add(new CoverPages.GroupOneCoverPage());
    
    var m1ItemPage = new ItemizedPage.GroupOneItems();
    m1ItemPage.ReportParameters.Clear();
    m1ItemPage.ReportParameters.Add(new ReportParameter("id", ReportParameterType.Integer, parentId));
    m1ItemPage.ReportParameters.Add(new ReportParameter("month", ReportParameterType.Integer, monthTriplet.Item1));
    this.Reports.Add(m1ItemPage);
 
    var m2ItemPage = new ItemizedPage.GroupOneItems();
    m2ItemPage.ReportParameters.Clear();
    m2ItemPage.ReportParameters.Add(new ReportParameter("id", ReportParameterType.Integer, parentId));
    m2ItemPage.ReportParameters.Add(new ReportParameter("month", ReportParameterType.Integer, monthTriplet.Item2));
    this.Reports.Add(m2ItemPage);
}

 and so on...
The first problem is that the parameterized constructor for the reportbook is never called as the report, only the default constructor.  This leads to the second issue which is that when I put a breakpoint on the constructor for the ObjectDataSource that backs the ItemizedPage.GroupOneItems report class, the exact same value is passed in for each of the months.  I'm not entirely sure how to fix this.  

Any thoughts?

Thanks.

7 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 15 Oct 2014, 12:00 PM
Hello Jonathan,

If you are using a TypeReportSource to pass a report to the viewer, internally we create an instance of the specified type through its default constructor. Also if you use the ASP.NET ReportViewer in an application with out-proc session state configuration, you will need to prove a default parameterless constructor - Design Considerations for Out-proc Session State.

To avoid the above issues, please check the Report Book Parameters
and set parameters to be mergeable (if you want the same Id to passed for all reports) or not mergeable (if you want to pass different values for the parameters named Id).

Non-mergeable parameters values can be passed as follows:
var TRS = new TypeReportSource { TypeName = typeof(MyReportBook).AssemblyQualifiedName };
TRS.Parameters.Add("report(0).Id",1);
TRS.Parameters.Add("report(1).Id",2);
TRS.Parameters.Add("report(2).Id",1);
 
reportViewer.ReportSource = TRS;


I hope the above information helps you.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Arne
Top achievements
Rank 1
answered on 01 Apr 2016, 02:28 PM

Hi,

Is it possible to get an example on how you would assign non-mergeable parameters using the html viewer ?

 

Regards 

Arne

0
Stef
Telerik team
answered on 01 Apr 2016, 03:22 PM
Hello Arne,

Please check the attached demo project. It uses Telerik Reporting v10.0.16.325. The version can be changed by running the Upgrade Wizard.

The code looks as follows:
//CS
 public class MyReportBook : Telerik.Reporting.ReportBook
    {
        public MyReportBook()
        {
            this.Reports.Add(new Report1());
            this.Reports.Add(new Report1());
            this.Reports.Add(new Report1());
        }
    }
 
//html
 <script type="text/javascript">
        $(document).ready(function () {
            $("#reportViewer1")
                .telerik_ReportViewer({
                    serviceUrl: "/api/reports/",
                    //ReportSource - report description
                    reportSource: {
                        report: "ReportBookParamsHTML5.Reports.MyReportBook, ReportBookParamsHTML5",
                        parameters: {                           
                             "reports(0).Parameter1Text": "First",
                            "reports(1).Parameter1Text": "Second",
                            "reports(2).Parameter1Text": "Third",
                            "reports(0).Parameter1": "test0",
                            "reports(1).Parameter1": "test1",
                            "reports(2).Parameter1": "test2"
                        }
        },                   
         viewMode: telerikReportViewer.ViewModes.INTERACTIVE,
        scaleMode: telerikReportViewer.ScaleModes.SPECIFIC,    
        scale: 1.0
        });
        });
    </script>

The used Report1 report has a Parameter1 report parameter that is visible and not mergeable.


If you want to provide more detailed description which report parameter is displayed in the viewer's Parameters area, you can change the report parameter's Text property by using an expression e.g. user function.
For example:
//user function
   public static string SetText(string entry)
        {
            return "Parameter " + entry;
        }
 
 
          //report1.designer.cs
           reportParameter1.Mergeable = false;
            reportParameter1.Name = "Parameter1Text";
            reportParameter1.Value = "design";
 
            reportParameter2.Mergeable = false;
            reportParameter2.Name = "Parameter1";
            reportParameter2.Text = "= ReportBookParamsHTML5.Reports.Report1.SetText(Parameters.Parameter1Text.Value)";
            reportParameter2.Visible = true;



Regards,
Stef
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
sriranga
Top achievements
Rank 1
answered on 06 Apr 2016, 04:44 PM

Hi stef i have requirement to show single report for n count (more than 1)

how to make it as dynamic rendering instead of  what u suggested in below snippet your example works for only 3 reports.

is there any other idea create object for Report1 depend upon some count

 

thanq you

public class MyReportBook : Telerik.Reporting.ReportBook
    {
        public MyReportBook()
        {
            this.Reports.Add(new Report1());
            this.Reports.Add(new Report1());
            this.Reports.Add(new Report1());
        }
    }

0
Stef
Telerik team
answered on 07 Apr 2016, 04:38 PM
Hi sriranga,

A ReportBook instance's Reports collection can be updated at run-time in code. Please check the related ReportBook help articles.

Regards,
Stef
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
Atul
Top achievements
Rank 1
answered on 20 Sep 2019, 06:58 PM

Hey stef,

Do we have any other solution of this problem apart from that is given in the link provided by you. Because it does not seems to be appropriate. I am facing the same problem.

0
Todor
Telerik team
answered on 25 Sep 2019, 12:35 PM

Hello Atul,

The solution for displaying multiple reports in a single document is the ReportBook. If you would like to modify the definitions of the reports in the report book you need to use a Custom Report Resolver. We have specified the necessary approach for accessing the report parameter values in the support ticket (#1431087) you opened for a similar topic. Generally, you need to include these values in the 'report' string that is a property of the client-side reportSource and extract those values in the Resolve() method.

Regards,
Todor
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
Tags
General Discussions
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Stef
Telerik team
Arne
Top achievements
Rank 1
sriranga
Top achievements
Rank 1
Atul
Top achievements
Rank 1
Todor
Telerik team
Share this question
or