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

Show ReportBook programmatically in ReportViewer

7 Answers 604 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 18 Mar 2009, 01:10 AM
Hi

I have a bunch of reports that are added to a Reportbook as follows:

 ReportBook reportBook = new ReportBook();
 reportBook.Reports.Add(report1);
reportBook.Reports.Add(report2);
reportBook.Reports.Add(report3);
...

I then assign reportbook to my ReportViewer1 control as follows:

 ReportViewer1.Report = reportBook;
        ReportViewer1.Report.DocumentName = "some name";
        ReportViewer1.DataBind();

The question is how to display the report book programmatically in the ReportViewer control?

A sample project or code snippet would be helpfull.

Thanks

Peter

7 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 18 Mar 2009, 08:09 AM
Hi Peter,

There is already a code snippet with programmatic creation of a report book in our help documentation. In fact there is a chapter on ReportBook covering everything you need to know about it.
"The question is how to display the report book programmatically in the ReportViewer control?" Here is a code snippet:

        ReportBook reportBook = new ReportBook();
        reportBook.Reports.Add(new Report2());
        reportBook.Reports.Add(new Report3());
        ReportViewer1.Report = reportBook;

Note that you should not call the DataBind() method as it is not applicable to the report viewer (inherited property).

Sincerely yours,
Steve
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Peter
Top achievements
Rank 1
answered on 18 Mar 2009, 11:25 AM
Hi Steve,

I saw that link but it doesn't hep me. I create the reports and add them to a report book.


   ReportViewer1.Report = reportBook;

my aspx control showing the report looks like this (see below)

            <telerik:ReportViewer ID="ReportViewer1" runat="server" Width="100%"
                Height="500px">
            </telerik:ReportViewer>
       

Am i forced to add a ReportBookControl to the aspx page? 

Peter
0
Steve
Telerik team
answered on 18 Mar 2009, 12:34 PM
Hello Peter,

The ReportBookControl is needed only if you are going to create the reportbook declaratively in your web site/app. If you are creating the ReportBook programmatically, like you do, the code sample from my previous reply would work fine. Can you elaborate what does not help you and what exactly is not working?
How/where do you create the reports which you add to the ReportBook? In your code you have:

reportBook.Reports.Add(report1);

Here report1 should be the instantiated report: MyReport report1 = new MyReport(); 

Best wishes,
Steve
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Peter
Top achievements
Rank 1
answered on 18 Mar 2009, 12:43 PM
Hi

I genererate various reports which i then combine into a single report using the following code (see below). So in the end i return one Report.

  Report report = GetCombinedReport(reportBook);
  reportBook.DocumentName = "some name";
  ReportViewer1.Report = report;

I expect to see all the reports as one in the Reportview (as it did before upgrading to Q1 2009 Telerik Reporting). I only see one empty page of the Master report. What is wronig with the code below which was working perfectly pre Q1 2009 version...

Peter

========================================================
private static Report GetCombinedReport(ReportBook reportBook)
    {
        Report report = new MasterReport();

       
        Unit unitX = Unit.Cm(0);
        Unit unitY = Unit.Cm(0);

        foreach (Report detailReport in reportBook.Reports)
        {
            DetailSection detailsubreport = (DetailSection)detailReport.Items["detail"];

            SubReport subReport;
            subReport = new SubReport();
            subReport.Location = new PointU(unitX, unitY);
            subReport.Size = new SizeU(Unit.Cm(18.97), detailsubreport.Height);  // margins of 2cm all around 
            subReport.ReportSource = detailReport;

            DetailSection detail = (DetailSection)report.Items["detail"];

            detail.Items.Add(subReport);

            // Set the gap between the report 1Cm
            unitY = unitY.Add(detailsubreport.Height.Add(Unit.Cm(0.5)));
        }
        // detail.Height = Unit.Cm(detailReports.Count + 1);
       
        return report;
    }
0
Steve
Telerik team
answered on 18 Mar 2009, 01:32 PM
Hi Peter,

There was no ReportBook prior to Q1 2009, so your GetCombinedReport() method was surely not accepting it as argument. What you are doing - looping through reports, creating subreport etc. has nothing to do with our ReportBook functionality, and it would seem that you are trying to do the combining of reports yourself, which is of course unnecessary now that you have this as built-in feature.

Sincerely yours,
Steve
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
G4SJack
Top achievements
Rank 1
answered on 27 Mar 2009, 03:49 AM
Hi Steve,

        ReportBook RptBook = new ReportBook();
        RptBook.Reports.Add(new report1(this.cboBranch.SelectedValue));
        this.ReportViewer1.Report = RptBook;

this.cboBranch.SelectedValue is the branch in the dropdownlist i choose, when i press display button, it will call the code mentioned above, but it always displaying the 1st branch record although i changed the branch to other.
Please advise.

Thanks.

0
Chavdar
Telerik team
answered on 30 Mar 2009, 09:46 AM
Hi G4STom,

To fix the problem please set the EnableViewState property of the ReportViewer to false. This is an issue with the viewer control which will be fixed for the service pack due in a couple of weeks.

We are sorry for the inconvenience.

Regards,
Chavdar
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Peter
Top achievements
Rank 1
Answers by
Steve
Telerik team
Peter
Top achievements
Rank 1
G4SJack
Top achievements
Rank 1
Chavdar
Telerik team
Share this question
or