Hierarchical tables can be easily merged using repeating merge blocks with 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. But what if the tables are very dynamic with a variable number of columns?

In this case, tables can be dynamically generated using the TX Text Control API by adding nested tables. This method can also be mixed with the MailMerge process by adding a placeholder in your template that will be replaced with the dynamically generated table.

JSON Data

Consider the following JSON data that should be used to generate the table.

Loading...

The data contains three hierarchical levels with two data rows on the first level. The JSON string is loaded and converted into a list of JObject elements returned by the DeserializeObject method of the JsonConvert class (Newtonsoft.Json). The CreateTable method is then called with the created list object.

Loading...

Recursively Adding Tables

The CreateTable method takes the hierarchical data and creates the tables. It is called recursively based on the current hierarchy level. A new table is added based on the number of columns in the current hierarchy level. For each row of data, a new table row is added and the values are added to the table cell text.

In the case where the data value is an array, a new nested table will be added by making a recursive call to the CreateTable method.

Loading...

Sample Data Results

When this method is called with the sample data, the following table structure will be created.

Creating tables with TX Text Control