New to Telerik Reporting? Request free 30-day trial

Insert PageBreak per N Records

Environment

Product Progress® Telerik® Reporting

Description

I want to insert a page break in the report after N amount of records. Currently, my report generates over 800 rows on a single page, but I want to display 100 rows per page. I don't have any applicable grouping field in my dataset, how can I achieve this?

Solution

The most commonly used data source component in reports is the SqlDataSource component. Many databases offer functions for counting the sequential number of a row within a partition of a result set such as the ROW_NUMBER function in SQL Server.

The ROW_NUMBER function can be used to add a custom field to the result set - GroupIdx that is increased for each N number of records that we need to insert a page break after, for example, the following SQL query returns 30 records and the grouping field is increased per 10 records.

SELECT
    (row_number() over (order by EmployeeID) -1)/10 as 'GroupIdx',
    [HumanResources].[vEmployee].[EmployeeID],
    [HumanResources].[vEmployee].[FirstName],
    [HumanResources].[vEmployee].[LastName],
    [HumanResources].[vEmployee].[JobTitle],
    [HumanResources].[vEmployee].[Phone]
FROM [HumanResources].[vEmployee]
WHERE [HumanResources].[vEmployee].[EmployeeID] <= 30
ORDER BY 1 ASC

Then, create a report/table group based on the GroupIdx field and set the group's PageBreak property to After so that a new page starts after each 10 records.

Additional Resources

Download the sample report from the reporting-samples repo.

See Also

In this article