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

Share page header on a report book.

2 Answers 169 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ben Casse
Top achievements
Rank 1
Ben Casse asked on 17 May 2011, 10:20 PM
Hey,

Is that possible to share the same page header and footer for all the reports which were added to a report book. Thanks.

2 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 20 May 2011, 01:47 PM
Hi Ben,

The report book functionality is combining different reports into one for the purposes of printing them at once or exporting them to a single file. Reports are displayed in the order they were added to the report book, but they do not become one in the sense of sharing sections or data. You would have to create the same page sections for each report that would be added to the report book in order to achieve your inquiry.

Regards,
Steve
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
David
Top achievements
Rank 1
Iron
answered on 07 Jul 2024, 06:17 PM

I know this question is 12+ years old, but I found myself looking for the same functionality.

There are two different ways you can accomplish this, but it requires some out-of-the-box thinking.

1) Have a method that will programmatically create your header, and use that function for all the reports in the report book. This is a bit tedious and doesn't provide the visual support that the Telerik Report Designer provides.

public void CreatePageHeader(Telerik.Reporting.Report report)
{
	var pageHeaderSection = GetItem<PageHeaderSection>(report.Items, "PageHeaderSection");
	
	var headerTextBox = new TextBox
	{
		Location = new PointU
		{
			X = new Unit(4.1, UnitType.Inch),
		},
		Size = new SizeU
		{
			Width = new Unit(2.889, UnitType.Inch),
			Height = new Unit(0.3, UnitType.Inch)
		}
	};

	headerTextBox.Name = "HeaderTextBox";
	headerTextBox.CanGrow = true;
	headerTextBox.Style.Font.Size = new Unit(20, UnitType.Point);
	headerTextBox.Style.Font.Bold = true;
	headerTextBox.Style.TextAlign = HorizontalAlign.Right;

	pageHeaderSection.Items.Add(headerTextBox);
}

2) Create a Header_Template.trdp and add your header components to it. Then programmatically copy the items from that header template, to each of the reports in the report book. This allows you to manage your header template in the Telerik Report Designer, and makes it easier to change it as opposed to the first approach I presented.

public void CopyHeaderTemplate(Telerik.Reporting.Report report)
{
	var headerTemplate = OpenReportTemplate("Header_Template.trdp");
	var headerTemplatePageHeaderSection = GetItem<PageHeaderSection>(headerTemplate.Items, "PageHeaderSection");
	var reportTemplatePageHeaderSection = GetItem<PageHeaderSection>(report.Items, "PageHeaderSection");

	foreach (var item in headerTemplatePageHeaderSection.Items)
	{
		reportTemplatePageHeaderSection.Items.Add(item);
	}
}

Please note that the GetItem<T>() method (used in both code examples above) is a helper method I created...

public T GetItem<T>(ReportItemBase.ItemCollection items, string itemName) where T : ReportItemBase
{
	if (items is null)
		throw new ArgumentNullException(nameof(items));

	if (string.IsNullOrWhiteSpace(itemName))
		throw new ArgumentNullException(nameof(itemName));

	var item = items[itemName];

	if (item is null)
		throw new Exception($"Unable to reference [{itemName}]");

	return (T)item;
}

Dimitar
Telerik team
commented on 10 Jul 2024, 01:03 PM

Thank you for sharing those approaches with the community!

I would also like to mention that if using a ReportBook is not a must, the desired functionality may be achieved using the SubReport Item. It does not render the page sections of the inner report, so the page header section of the main report will be rendered instead on each page.

Tags
General Discussions
Asked by
Ben Casse
Top achievements
Rank 1
Answers by
Steve
Telerik team
David
Top achievements
Rank 1
Iron
Share this question
or