Example - Creating a Master-Detail Report

ASP.NET User's Guide > Reporting and Mail Merge (DocumentServer.MailMerge)

A Master-Detail report renders data from a hierarchical data source such as related tables or nested objects.

This example is part the Sample Explorer project which includes all samples in one. The sources for this sample project can be found here:

Language Project Location
C# %USERPROFILE%\Documents\TX Text Control 26.0.NET Server for ASP.NET\Samples\ASP.NET\CSharp\Sample Explorer\
VB.NET %USERPROFILE%\Documents\TX Text Control 26.0.NET Server for ASP.NET\Samples\ASP.NET\VB.NET\Sample Explorer\

You will find the source code and the ASPX page of this sample in the Solution structure tree under: Reporting\masterdetail.aspx

Example description

Nested related tables are recognized automatically and merged based on the merge block names in the template. The following report lists all sales and the sold products for each sale. Each sale is rendered on a new page in the final report.

Click on the button Create report to start the merge process.

The sample database from the tutorial is used in this sample as well. The template consists of a table with 3 rows. The last row is a merge block (indicated through the red overlay background color) that should list all products.

The complete template is repeated based on the number rows of the master table. The master table is passed in the Merge method and TX Text Control is matching the related tables automatically.

The resulting document is loaded into a DocumentViewer instance on the ASPX page.

protected void btn_CreateReport_Click(object sender, EventArgs e)
    // open the sample XML file and create DataSet
    DataSet ds = new DataSet();
    ds.ReadXml(Server.MapPath("/datasource/sample_db.xml"), XmlReadMode.Auto);

    // load the template

    // pass the master table to start the merge process

    byte[] data;

    // save the document to memory as PDF
    mailMerge1.SaveDocumentToMemory(out data,
        TXTextControl.BinaryStreamType.InternalUnicodeFormat, null);


    // store document for a later download
    Session["data"] = data;
    btnDownloadPDF.Visible = true;
[Visual Basic]
Protected Sub btn_CreateReport_Click(sender As Object, e As EventArgs)
    ' open the sample XML file and create DataSet
    Dim ds As New DataSet()
    ds.ReadXml(Server.MapPath("/datasource/sample_db.xml"), XmlReadMode.Auto)

    ' load the template
    mailMerge1.LoadTemplate(Server.MapPath("/documents/template_master.docx"), _

    ' pass the master table to start the merge process

    Dim data As Byte()

    ' save the document to memory as PDF
    mailMerge1.SaveDocumentToMemory(data, _
        TXTextControl.BinaryStreamType.InternalUnicodeFormat, Nothing)

    DocumentViewer2.LoadDocumentFromMemory(data, _

    ' store document for a later download
    Session("data") = data
    btnDownloadPDF.Visible = True
End Sub