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:

public class Report
{
public string Name { get; set; }
public List<Product> Products { get; set; }
}
public class Product
{
public string Name { get; set; }
public float Price { get; set; }
}
view raw data.cs hosted with ❤ by GitHub

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 property TX Text Control .NET for Windows Forms
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.

List<Report> reports = new List<Report>();
Report report1 = new Report()
{
Name = "Test Report",
Products = new List<Product>() {
new Product() { Name = "TX Text Control Product 1", Price = 634.34F },
new Product() { Name = "TX Text Control Product 2", Price = 34.34F },
}
};
Report report2 = new Report()
{
Name = "Test Report2",
};
reports.Add(report1);
reports.Add(report2);
view raw data.cs hosted with ❤ by GitHub

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:

public class Report
{
public string Name { get; set; }
public bool RenderProducts { get; set; }
public List<Product> Products { get; set; }
}
public class Product
{
public string Name { get; set; }
public float Price { get; set; }
}
view raw data.cs hosted with ❤ by GitHub

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 TX Text Control .NET for Windows Forms
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:

reports = new List<Report>();
Report report1 = new Report()
{
Name = "Test Report",
RenderProducts = true,
Products = new List<Product>() {
new Product() { Name = "TX Text Control Product 1", Price = 634.34F },
new Product() { Name = "TX Text Control Product 2", Price = 34.34F },
}
};
Report report2 = new Report()
{
Name = "Test Report2",
RenderProducts = false,
Products = new List<Product>() {
new Product() { Name = "TX Text Control Product 1", Price = 634.34F },
new Product() { Name = "TX Text Control Product 2", Price = 34.34F },
}
};
reports.Add(report1);
reports.Add(report2);
view raw data.cs hosted with ❤ by GitHub

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

MergeBlockInfo mergeBlockInfo = new MergeBlockInfo("Products");
mergeBlockInfo.BlockMergingCondition =
new List<TXTextControl.DocumentServer.DataShaping.FilterInstruction>()
{
new TXTextControl.DocumentServer.DataShaping.FilterInstruction(
"RenderProducts",
TXTextControl.DocumentServer.DataShaping.RelationalOperator.Equals,
true
)
};
mergeBlockInfo.ColumnNames =
ribbonReportingTab1.DataSourceManager.PossibleMergeFieldColumns.Select(
column => column.ColumnName).ToList();
MergeBlockSettings settings = new MergeBlockSettings(BlockTemplateType.PlainParagraph);
ribbonReportingTab1.DataSourceManager.InsertMergeBlock(textControl1, mergeBlockInfo, settings);
view raw data.cs hosted with ❤ by GitHub

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

Template