Report Book, Report Instances and Parameters

6 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    11 posts
    Member since:
    Apr 2014

    Posted 10 Oct 2014 Link to this post

    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.

  2. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 15 Oct 2014 Link to this post

    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.

     
  3. DevCraft banner
  4. Arne
    Arne avatar
    1 posts
    Member since:
    Apr 2016

    Posted 01 Apr in reply to Stef Link to this post

    Hi,

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

     

    Regards 

    Arne

  5. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 01 Apr Link to this post

    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
  6. sriranga
    sriranga avatar
    1 posts
    Member since:
    Dec 2014

    Posted 06 Apr in reply to Stef Link to this post

    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());
            }
        }

  7. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 07 Apr Link to this post

    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
Back to Top
DevCraft banner