The Merge method of the MailMerge class merges all records into a single document by default.

The boolean parameter append specifies whether all resulting documents should be merged into one resulting document or split into separate documents.

public void Merge(System.Data.DataTable mergeData, bool append)
view raw tx.cs hosted with ❤ by GitHub

When MailMerge is connected to a TextComponent such as the visual TXTextControl.TextControl, the resulting document is loaded back into the connected Text Control. In case the Merge method has been used with the append parameter false, only the last created document is loaded back into the Text Control.

In order to access each single created document, the DataRowMerged event can be used to save the resulting, single document in this event. The event arguments DataRowMergedEventArgs return the merged document in the internal TX Text Control format that can be accessed using the MergedRow property.

The following sample shows how to use the event by merging the following simple template consisting of two merge fields:

The append parameter of the Merge method explained

As a data source, a simple DataSet with one DataTable is used. Before the Merge method is called with the append parameter set to false, the DataRowMerged event is attached:

DataTable dt = new DataTable();
dt.Rows.Add(new string[] { "Text Control", "Peter Jackson" });
dt.Rows.Add(new string[] { "Microsoft", "Sue Williamson" });
dt.Rows.Add(new string[] { "Google", "Peter Gustavsson" });
mailMerge1.DataRowMerged += mailMerge1_DataRowMerged;
mailMerge1.Merge(dt, false);
view raw tx.cs hosted with ❤ by GitHub

In the DataRowMerged event, each merged record is loaded into a temporary ServerTextControl and saved as HTML which is then sent back to the browser using HttpResponse:

void mailMerge1_DataRowMerged(object sender,
TXTextControl.DocumentServer.MailMerge.DataRowMergedEventArgs e)
string htmlDocument = "";
using (TXTextControl.ServerTextControl tx =
new TXTextControl.ServerTextControl())
tx.Save(out htmlDocument, TXTextControl.StringStreamType.HTMLFormat);
Response.Write("<hr />");
view raw tx.cs hosted with ❤ by GitHub

The resulting HTML shows the 3 merged records divided by an horizontal rule:

The append parameter of the Merge method explained

Download the sample from GitHub and test it on your own.