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

Accessing a Report's Properties and Methods from ReportViewer

1 Answer 99 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 08 Jun 2015, 07:08 PM

What is the recommended way to access properties and methods on a report class from a report viewer?

For example:

MyReportBase :  Telerik.Reporting.Report

public string ReportTitle

public string GetNumberOfRecords() 

 

MyReportClass : MyReportBase

 

Form MyReportViewer has a radReportViewer control on it.

Suppose I want my form to set it's title to be myReport.ReportTitle + " - " + myReport.GetNumberOfRecords() + "records"

eg Client List - 127 records

The radReportViewer control is using the InstanceReportSource type for the report source. 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 11 Jun 2015, 11:58 AM
Hello Matt,

In general, expressions used in the report are evaluated on processing the report. Then the report is rendered and pages, and you can obtain the number of pages of the document - Report Life Cycle.

Thus the properties used in your example are known later in time, after the report is displayed in the viewer.


If you want to change a literal or other in the form, you can use the ASP.NET WebForms Client-side API to get the number of rendered pages, and also to access the displayed report's Name or DocumentName property. For example:
//if the report is set as follows
 if (!IsPostBack)
    {
        //TypeReportSource reportSource = new TypeReportSource();
        //reportSource.TypeName = typeof(ReportCatalog).AssemblyQualifiedName;
 
        var reportSource = new InstanceReportSource();
        reportSource.ReportDocument = new ReportCatalog() { DocumentName="MyReport"};
        this.ReportViewer1.ReportSource = reportSource;
    }
 
//change the TITLE of the page on loading the report
 <script type="text/javascript">
                ReportViewer.OnReportLoadedOld = ReportViewer.OnReportLoaded;
                ReportViewer.prototype.OnReportLoaded = function () {
                    this.OnReportLoadedOld();
 
                    var viewer = <%=ReportViewer1.ClientID%>;
                    $('title').html( viewer.get_TotalPages()+'<%=(ReportViewer1.ReportSource as Telerik.Reporting.InstanceReportSource).ReportDocument.DocumentName  %>');
                }
            </script>


In case you are using the HTML5 viewer, you can use the exposed data attributes to get the number of pages of the report. There are also events like renderingEnd where you can update the page.


If you need further help, please elaborate on the scenario and the customizations in the report. Feel free to open a support ticket and send us a demo project to check your settings.

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
Tags
General Discussions
Asked by
Matt
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or