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.

Loading...

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:

Loading...

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:

Loading...

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.

GitHub

Download and Fork This Sample on GitHub

We proudly host our sample code on github.com/TextControl.

Please fork and contribute.

Requirements for This Sample

  • Visual Studio 2015 or better
  • TX Text Control .NET Server for ASP.NET (trial sufficient)