Typically, a merge block is used to repeat content such as table rows. But a merge block can be also used to control the rendering of a complete block such as a sub report.

Remove merge blocks by removing data

Consider the following data model:

Loading...

The following screenshot shows the simple template for this sample. Highlighted in red, the merge block is shown:

Template

The following code creates two instances of the data model. The first Report has a Products list and the second doesn't. If the MailMerge property TXTextControl.DocumentServer.MailMerge.RemoveEmptyBlocks is set to true (default), the missing data controls the rendering of the complete block.

Loading...

In the results, you can see that the Products section gets rendered in the first report, but is completely removed in the second report:

Template

If the data is missing, the merge block gets removed.

Render merge blocks based on conditions

Another way to control the merge block rendering is to compare a value of the merge block's parent table. Therefore, we change the data model a little bit:

Loading...

A boolean value has been added to the parent object that should control whether the merge block is rendered or not.

The TXTextControl.DocumentServer.DataSources.MergeBlockInfo.BlockMergingCondition property sets a condition the parent data row of this merge block has to satisfy, so that this merge block is merged at all.

The following codes creates the new data object. The Products data part is now available in both objects, but RenderProducts is used to specify whether the block is rendered or not:

Loading...

This code is used to insert the merge block with the condition (if "RenderProducts" = true):

Loading...

The results are the same. The merge block is rendered in the first case and it is not rendered in the second case:

Template