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:
The following screenshot shows the simple template for this sample. Highlighted in red, the merge block is shown:
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 TXText
╰ DocumentServer Namespace
╰ MailMerge Class
╰ RemoveEmptyBlocks Property
Specifies whether the content of empty merge blocks should be removed from the template or not. is set to true (default), the missing data controls the rendering of the complete block.
In the results, you can see that the Products section gets rendered in the first report, but is completely removed in the second report:
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:
A boolean value has been added to the parent object that should control whether the merge block is rendered or not.
╰ DocumentServer.DataSources Namespace
╰ MergeBlockInfo Class
╰ BlockMergingCondition Property
Gets or sets a condition the parent data row of this merge block has to satisfy so that this merge block is merged at all. 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:
This code is used to insert the merge block with the condition (if "RenderProducts" = true):
The results are the same. The merge block is rendered in the first case and it is not rendered in the second case: