Reporting: Removing Empty Table Rows
A valuable advantage of the Text Control Reporting Framework is the flexibility through programmability. Developers can use the power of the TX Text Control API during the merge process. While merge fields are populated, an event is fired for each merge field, data row or block row. This gives you the flexibility to manipulate the merge process, to inject formatted text or to remove unnecessary elements. In this sample, NEXT fields are used to realize alternate row colors. The advantage of…

A valuable advantage of the Text Control Reporting Framework is the flexibility through programmability. Developers can use the power of the TX Text Control API during the merge process. While merge fields are populated, an event is fired for each merge field, data row or block row. This gives you the flexibility to manipulate the merge process, to inject formatted text or to remove unnecessary elements.
In this sample, NEXT fields are used to realize alternate row colors. The advantage of this concept is that you can have not only 2 rows with different styles, but unlimited number of table rows with a different background color for instance. The following screenshot shows the template with the NEXT field at the end of the first row of the block (light gray row):

The two table rows have the same merge fields. During the merge process, the NEXT field increases the current data row by 1 which results in alternating row colors:

As you can see in the above screenshot, this concept might insert an empty row at the end of the table in case the row count is uneven.
Thanks to the flexibility, this row can be removed in the BlockRowMerged event:
private void mailMerge1_BlockRowMerged(object sender,
TXTextControl.DocumentServer.MailMerge.BlockRowMergedEventArgs e)
{
byte[] data;
// create a temporary ServerTextControl to access API
using (ServerTextControl tx = new ServerTextControl())
{
tx.Create();
tx.Load(e.MergedBlockRow, BinaryStreamType.InternalUnicodeFormat);
if (tx.Tables.GetItem() == null)
return;
Table table = tx.Tables.GetItem();
// loop through row and remove empty rows
foreach (TableRow row in table.Rows)
{
row.Select();
if (tx.Selection.Length == table.Columns.Count)
{
tx.Selection.Length = 0;
table.Rows.Remove();
}
}
tx.Save(out data, BinaryStreamType.InternalUnicodeFormat);
}
// return the manipulated merged block
e.MergedBlockRow = data;
}

You can download the Visual Studio 2012 sample project and test this on your own. At least, a trial version of TX Text Control .NET for Windows Forms X11 is required.
Reporting
The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.
Related Posts
Creating Your First ASP.NET Reporting Application
This tutorial shows how to use the MailMerge component in an ASP.NET Web application to merge a template with data to create an Adobe PDF document.
New Online Sample: Build your First Report
We published a new online demo that shows how to create a report including preparing data, creating a template to merging them together.
ReportingDocumentationReportingCloud
Create your First Document with ReportingCloud
As part of our new ReportingCloud documentation, we published a guided tutorial that shows how to create a document without programming.
MailMerge: Starting Each Merge Block on a New Page
A merge block is repeated based on the number of matching data rows in the hierarchical data object. The complete merge block is cloned and inserted under the original location in the template.…
Using MailMerge with JSON Data
In the last article, we explained how to create an ASP.NET Web API to merge templates with JSON data in the payload body of an HTTP request. The focus of this article was on the Web API and…