Products Technologies Demo Docs Blog Support Company

MailMerge: Removing Empty Blocks

In version X13, a new property has been introduced that specifies whether the content of empty merge blocks should be removed from the template or not: RemoveEmptyBlocks. This can be very helpful for dynamic templates where under specific circumstances, a complete block should be rendered or not. Consider the following sample class structure that is used as the merge data object: The name of the dynamic block in the template is Appendix and the master object is Data. If the property Appendix…

MailMerge: Removing Empty Blocks

In version X13, a new property has been introduced that specifies whether the content of empty merge blocks should be removed from the template or not: RemoveEmptyBlocks. This can be very helpful for dynamic templates where under specific circumstances, a complete block should be rendered or not.

Consider the following sample class structure that is used as the merge data object:

public class Data
{
    public string Field { get; set; }
    public Appendix Appendix { get; set; }
}

public class Appendix
{
    public string Field1 { get; set; }
}

The name of the dynamic block in the template is Appendix and the master object is Data. If the property Appendix of the class Data has been set to a valid object of type Appendix, the block data exists and is merged.

Appendix appendix = new Appendix()
{
    Field1 = "Field 1 Text"
};

Data data = new Data() {
    Field = "Field Text",
    Appendix = appendix
};

using (MailMerge mailMerge1 = new MailMerge())
{
    mailMerge1.TextComponent = textControl1;
    mailMerge1.RemoveEmptyBlocks =
        removeEmptyBlocksToolStripMenuItem.Checked;
    mailMerge1.MergeObject(data);
}

If the property RemoveEmptyBlocks of MailMerge is set to true (code line 14) and the merge data is missing (code line 8), the complete block gets removed.

This new concept allows you to create dynamic structures and conditional blocks in a template. Merge blocks are not necessarily blocks that repeat content. Using merge blocks, you can also define a named range of formatted text with data from another object.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Reporting

The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.

See Reporting products

Related Posts

ASP.NETReportingMail Merge

MailMerge Class Settings Explained

This article explains the different settings of the MailMerge class and how and when they should be used.


ReportingWindows FormsExcel

Merge Excel Documents into MailMerge Templates using IncludeText Fields

This sample shows how to use IncludeText fields to merge Excel documents into templates using MailMerge.


ASP.NETReportingWindows Forms

MailMerge: Conditional Table Cell Colors using Filter Instructions

The MailMerge class provides an extensible framework to inject custom logic to the merge process. This sample shows how to implement conditional table cell colors.


ASP.NETReportingWindows Forms

MailMerge: Using Filters to Remove Unwanted Rows

Data in merge blocks can be filtered and sorted. This article explains how to use filters to remove unwanted lines.


ReportingWindows FormsMail Merge

MailMerge: Conditional Rendering of Merge Blocks

Merge blocks can be used to render content conditionally. This article explains different ways to control this.