The MailMerge TX Text Control .NET Server for ASP.NET
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.
class provides a very effective way to merge data into merge field placeholders, repeating blocks, form fields, barcodes, images and chart objects. This engine handles the dynamic generation of documents based on document templates.

This article explains the data structure based on a simple template and sample JSON data.

The Sample JSON Data

The sample JSON data contains hierarchical data that allows to show different mail merge features including access to data from child tables and nested, repeating merge blocks.


Internally, the hierarchical structure is converted into tables. The following diagram shows these tables including their child tables:

Sample data

The Sample Template

The sample template that is used in this article is very simple and contains static data, simple merge fields and a nested, repeating block. The merge block will list all "orders" from the sample data:

Sample template

First, we take a look at the address part of the template. For this part, 3 tables are used and accessed in different ways.

Sample template

Accessing Child Tables

company_name comes from the root table directly while the address is coming from a child table. These fields can be accessed using the "dot notation". For example, to access the street, the merge field name is address.street.

The contacts part contains a merge block (highlighted in red below) to list all of the contacts. A merge block repeats all elements part of the block based on the data for this block. In this case, the block includes a soft break and the tab character, so that all contacts are listed at the same indent position:

Sample template

The following animation shows the header section before and after the merge process:

Sample template

Repeating Blocks

The detail section lists all orders and their articles. Therefore, two nested merge blocks are inserted. The outer block repeats the orders objects and the inner block lists all articles:

Sample template

As can be seen in the following animation, the outer block is getting repeated 2 times based on the actual data in the given JSON. The inner table row is defined as the nested block articles and contains all line items:

Sample template

Using Dynamic Formulas in Merge Blocks

Several values are calculated on-the-fly and are not part of the JSON data:

Sample template

The line total and the total sum values are calculated based on table cell formulas. The line total multiplies the qty with the product.price including the given discount. The total sum formula simply creates a sum of all values above in the same column of the table.

The IF field prints the text "This item is discounted!" in cases the discount is larger than 20%.

Download Sample Data

Download the sample template and the JSON data and test this on your own.