Typically, a merge block is used to repeat content such as table rows. The Mail ╰ 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 is using the hierarchical data to repeat the content and to populate fields with data in that block. This merge block provides 3 different options that can be controlled:
- Filters
- Sorting
- Rendering conditions
Those options can be defined through a dialog box or when adding a merge block programmatically through the Merge ╰ TX Text Control .NET Server for ASP.NET
╰ DocumentServer.DataSources Namespace
╰ MergeBlockInfo Class
The MergeBlockInfo class is used to insert a table or paragraph based repeating merge block into a TextControl instance using the DataSourceManager.InsertMergeBlock method. class.
MergeBlockInfo Class
An extension in version X19 provides a way to create a MergeBlockInfo instance based on an existing merge block Sub ╰ TX Text Control .NET Server for ASP.NET
╰ TXTextControl Namespace
╰ SubTextPart Class
A SubTextPart object represents a user-defined part of a TX Text Control document. .
Consider the following JSON string as the data source:
[ | |
{ | |
"items": [ | |
{ | |
"id": 1, | |
"status": "", | |
"calibrated": 1521135120000, | |
"location": { | |
"latitude": -117.125, | |
"longitude": 31.125 | |
} | |
}, | |
{ | |
"id": 2, | |
"status": "offline", | |
"calibrated": 1521638100000, | |
"location": { | |
"latitude": -113.325, | |
"longitude": 33.325 | |
} | |
}, | |
{ | |
"id": 3, | |
"status": "error", | |
"calibrated": 1522291320000, | |
"location": { | |
"latitude": -111.625, | |
"longitude": 35.625 | |
} | |
} | |
] | |
} | |
] |
The following screenshot shows a nested merge block including the blocks items and location:
The inner merge block location should be only rendered, if the id of the parent block (items) is > 1.
Manipulate MergeBlock Conditions
The following code shows how to retrieve a SubTextPart and to create a new MergeBlockInfo object to apply the required merge condition:
// find the SubTextPart | |
SubTextPart mergeBlock = textControl1.SubTextParts.GetItem("txmb_location"); | |
// create a new MergeBlockInfo object from SubTextPart | |
TXTextControl.DocumentServer.DataSources.MergeBlockInfo mbInfo = | |
new TXTextControl.DocumentServer.DataSources.MergeBlockInfo(mergeBlock); | |
// add a condition: | |
// render block, if "id" from parent is greater than 1 | |
mbInfo.BlockMergingCondition.Add( | |
new TXTextControl.DocumentServer.DataShaping.FilterInstruction( | |
"id", | |
TXTextControl.DocumentServer.DataShaping.RelationalOperator.GreaterThan, | |
1)); | |
// apply conditions | |
mbInfo.Apply(); |
When the template is merged using MailMerge, you can see that the first inner merge block is not merged while the other 2 blocks are merged as they match the condition (id > 1):
Stay tuned for more improvements and new features of TX Text Control X19!