Adding pages in code

Stimulsoft Reports.NET discussion
Post Reply
mscenna
Posts: 6
Joined: Mon Jul 10, 2006 10:24 am

Adding pages in code

Post by mscenna »

Hi,

I am trying to add two identical report layouts together and printing them off as one report. The problem I am trying to solve is that I have a report that has an arbitrary number of pages that all have the same template. Currently I am doing something like this:

r.Load(Server.MapPath("Templates\\" + dp.FileString + ".mrt"));

StiReport r2 = new StiReport();
r2.Load(Server.MapPath("Templates\\" + dp.FileString + ".mrt"));
r2.Compile();
r2["Address"] = "TEST";
Stimulsoft.Report.Components.StiPage page = new Stimulsoft.Report.Components.StiPage(r2);

page.Components = r2.Pages[0].Components;
page.Name = "Page2";

r.Pages.Add(page);
r.Compile();
r.Render();

The problem I am having was obvious to me. Since the report layouts are exactly the same, they define the same objects in their scripts and so when you try to compile the two of them together you get a compile error since there will be duplicate definitions of the components.

Is there another solution to this problem?
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Adding pages in code

Post by Vital »

Add this code:


r.Pages.Add(page);



StiComponentsCollection comps = page.GetComponents();
int index = 0;
foreach (StiComponent comp in comps)
{
comp.Name = "Comp" + index++.ToString();
comp.Page = page;
comp.Report = r;
if (comp.Parent is StiPage)comp.Parent = page;
}


r.Compile();

Post Reply