Typically, a merge block is used to repeat content based on data rows of a specific table or child table. Merge blocks can be also used to group elements for various reasons. One reason could be the conditional rendering of merge blocks.

This article describes how to add a merge block programmatically using the TXTextControl.DocumentServer.DataSources.DataSourceManager.InsertMergeBlock method TX Text Control .NET for Windows Forms
DocumentServer.DataSources Namespace
DataSourceManager Class
InsertMergeBlock Method
Inserts a repeating merge block into a TextControl instance, a WPF.TextControl instance or a ServerTextControl instance at the current input position.
and how to set filters and sorting instructions. Additionally, block merging conditions are introduced to specify whether a merge block is rendered or not.

In this article, the following simple data structure is used as the data source:

Loading...

On loading, a new data object is created and loaded into the TXTextControl.DocumentServer.DataSources.DataSourceManager class TX Text Control .NET for Windows Forms
DocumentServer.DataSources Namespace
DataSourceManager Class
The DataSourceManager class is designed for handling all existing kinds of data sources which can be used together with the MailMerge class.
which is designed for handling all existing kinds of data sources used together with the TXTextControl.DocumentServer.MailMerge class TX Text Control .NET for Windows Forms
DocumentServer Namespace
MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services.
. The available merge block table names are listed in a combo box.

Loading...

DataSourceManager

To insert a new merge block programmatically, the TXTextControl.DocumentServer.DataSources.DataSourceManager.InsertMergeBlock method TX Text Control .NET for Windows Forms
DocumentServer.DataSources Namespace
DataSourceManager Class
InsertMergeBlock Method
Inserts a repeating merge block into a TextControl instance, a WPF.TextControl instance or a ServerTextControl instance at the current input position.
can be used. The following code inserts a merge block with all available merge fields and some filter and sorting instructions:

Loading...

DataSourceManager

There are three conditions in the merge block defined:

  1. Sorting: The table is sorted ascending by the column Price.
  2. Filtering: Only rows are rendered where the column Price is greater than 500.
  3. Conditions: The whole block is only rendered, if the column Name of the parent table is Test Report.

The document is then merged using the TXTextControl.DocumentServer.MailMerge.MergeObject method TX Text Control .NET for Windows Forms
DocumentServer Namespace
MailMerge Class
Merge Method
Merges a single instance of an arbitrary type into the loaded document template.
:

Loading...

DataSourceManager

These new merge block settings can be used to handle data shaping in the template directly and to render parts of a document conditionally based on merge field values in the data source. No custom event handling is required anymore to set the conditions for a merge block.

Test this on your own and download a trial version of TX Text Control X16.