# Flow Type Layout Reporting Series: Master-detail Relationship Blocks

> Nested repeating blocks in TX Text Control enable master-detail reporting for one-to-many relationships. Each block name maps to a DataTable, and DataRelations link parent-child data automatically. C# code demonstrates building a DataSet with related tables and calling MergeBlocks.

- **Author:** Bjoern Meyer
- **Published:** 2013-04-06
- **Modified:** 2026-03-05
- **Description:** Nested repeating blocks in TX Text Control enable master-detail reporting for one-to-many relationships. Each block name maps to a DataTable, and DataRelations link parent-child data automatically. C# code demonstrates building a DataSet with related tables and calling MergeBlocks.
- **4 min read** (627 words)
- **Tags:**
  - Tutorial
- **Web URL:** https://www.textcontrol.com/blog/2013/04/06/flow-type-layout-reporting-series-master-detail-relationship-blocks/
- **LLMs URL:** https://www.textcontrol.com/blog/2013/04/06/flow-type-layout-reporting-series-master-detail-relationship-blocks/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2013/04/06/flow-type-layout-reporting-series-master-detail-relationship-blocks/llms-full.txt

---

![Blog Series: Flow Type Layout Reporting](https://s1-www.textcontrol.com/assets/dist/blog/2013/04/06/a/assets/blog_series_reporting.webp "Blog Series: Flow Type Layout Reporting")A master-detail relationship is a 1:n (one-to-many) type relationship. A typical example for such a relationship is a purchase order and a set of items that belongs to each purchase order. This allows you to create complex nested reports in a very easy way.

TX Text Control's **repeating blocks** can be nested in unlimited levels. Those nested blocks can be inserted in the same way like usual merge blocks.

Each block has an unique name which should match the name of a **DataTable** in the merge data. If nested blocks with an existing **DataRelation** are recognized, they are combined automatically. The following screenshot shows the concept of nested blocks and the data relations:

![Master-detail relationship blocks](https://s1-www.textcontrol.com/assets/dist/blog/2013/04/06/a/assets/article_1.webp "Master-detail relationship blocks")The range from the green start bookmark to the green end bookmark is the outer block representing article groups. The inner block is marked with blue markers.

*Marker colors are for visualization purposes only. In TX Text Control, all markers are gray.*

Looking at the merged results show that the articles are mapped automatically:

![Master-detail relationship blocks](https://s1-www.textcontrol.com/assets/dist/blog/2013/04/06/a/assets/article_2.webp "Master-detail relationship blocks")The Merge Data Structure
------------------------

The block data consists of two tables with an unique relationship (*article\_group\_id*):

![Master-detail relationship blocks](https://s1-www.textcontrol.com/assets/dist/blog/2013/04/06/a/assets/article_7.webp "Master-detail relationship blocks")Inserting the Nested Blocks
---------------------------

1. In **TX Text Control Words**, insert a table as shown below with a merge field in a cell from the outer data table.
    
    ![Master-detail relationship blocks](https://s1-www.textcontrol.com/assets/dist/blog/2013/04/06/a/assets/article_3.webp "Master-detail relationship blocks")
2. Select the table and 2 blank lines under the table and choose *Insert Merge Block* from the *Merge Block* ribbon group.
    
    ![Master-detail relationship blocks](https://s1-www.textcontrol.com/assets/dist/blog/2013/04/06/a/assets/article_4.webp "Master-detail relationship blocks")
    
    In the opened dialog box, type in the name of the outer **DataTable** and confirm with *OK*.
    
    ![Master-detail relationship blocks](https://s1-www.textcontrol.com/assets/dist/blog/2013/04/06/a/assets/article_5.webp "Master-detail relationship blocks")
3. Insert another table below the existing table and add fields from the inner data table. Select the whole table row in order to insert another block called *Article*.
    
    ![Master-detail relationship blocks](https://s1-www.textcontrol.com/assets/dist/blog/2013/04/06/a/assets/article_6.webp "Master-detail relationship blocks")

The following code shows how to build the data, the data relationships and how to merge these blocks using TX Text Control's Reporting classes:

```
DataSet dsBlockData = new DataSet();

// article group
DataTable dtGroup = new DataTable("Group");
dtGroup.Columns.Add("article_group_id");
dtGroup.Columns.Add("article_group_name");

dtGroup.Rows.Add(new object[] { 1, "Vegetables" });
dtGroup.Rows.Add(new object[] { 2, "Fruits" });

// article
DataTable dtArticle = new DataTable("Article");
dtArticle.Columns.Add("article_group_id");
dtArticle.Columns.Add("article_name");
dtArticle.Columns.Add("article_description");
dtArticle.Columns.Add("article_price");

dtArticle.Rows.Add(new object[] { 1, "Asparagus",
    "Asparagus officinalis is a spring vegetable.", "110" });
dtArticle.Rows.Add(new object[] { 1, "Potato",
    "The potato is a starchy crop of the Solanaceae family.", "220" });
dtArticle.Rows.Add(new object[] { 1, "Carrot",
    "The carrot is a root vegetable, usually orange in colour.", "330" });
dtArticle.Rows.Add(new object[] { 2, "Apple",
    "The apple is the pomaceous fruit of the apple tree.", "440" });
dtArticle.Rows.Add(new object[] { 2, "Strawberry",
    "The strawberry is a hybrid species.", "550" });

dsBlockData.Tables.Add(dtGroup);
dsBlockData.Tables.Add(dtArticle);

DataRelation drGroupArticle = new DataRelation("GroupArticle",
    dsBlockData.Tables["Group"].Columns["article_group_id"],
    dsBlockData.Tables["Article"].Columns["article_group_id"]);

dsBlockData.Relations.Add(drGroupArticle);

mailMerge1.MergeBlocks(dsBlockData);
mailMerge1.Merge(null, true);
```

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Windows Forms Tutorial: Create Your First Windows Forms C# Application](https://www.textcontrol.com/blog/2024/08/26/windows-forms-tutorial-create-your-first-windows-forms-csharp-application/llms.txt)
- [How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/16/how-to-mail-merge-ms-word-docx-documents-in-aspnet-core-csharp/llms.txt)
- [Creating an Angular Document Editor Application with a Node.js WebSocket Server](https://www.textcontrol.com/blog/2023/08/24/creating-an-angular-document-editor-application-with-a-nodejs-websocket-server/llms.txt)
- [Adding SVG Watermarks to Documents](https://www.textcontrol.com/blog/2022/01/28/adding-svg-watermarks-to-documents/llms.txt)
- [Using MailMerge in ASP.NET Core 6 Web Applications](https://www.textcontrol.com/blog/2022/01/27/using-mailmerge-in-aspnet-core-6-web-applications/llms.txt)
- [DocumentViewer for React Prerelease](https://www.textcontrol.com/blog/2020/10/27/document-viewer-for-react-prerelease/llms.txt)
- [New DocumentViewer Signature Tutorial Sample](https://www.textcontrol.com/blog/2020/08/18/new-documentviewer-signature-tutorial-sample/llms.txt)
- [Creating an ASP.NET MVC DocumentViewer Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-documentviewer-application-with-razor/llms.txt)
- [Creating Your First Windows Forms Application with C#](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-windows-forms-application-with-csharp/llms.txt)
- [Creating Your First WPF Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-wpf-application/llms.txt)
- [Creating a WPF Ribbon Application](https://www.textcontrol.com/blog/2020/01/01/creating-a-wpf-ribbon-application/llms.txt)
- [Integrate Document Editing into any HTML Client using the HTML Widget](https://www.textcontrol.com/blog/2020/01/01/integrate-document-editing/llms.txt)
- [Creating an ASP.NET MVC Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-application-with-razor/llms.txt)
- [Creating A Windows Forms Ribbon Application](https://www.textcontrol.com/blog/2020/01/01/creating-a-windows-forms-ribbon-application/llms.txt)
- [Creating Your First ASP.NET Reporting Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/llms.txt)
- [Creating an ASP.NET Web Forms AJAX Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-web-forms-ajax-application/llms.txt)
- [Creating a WebSocket Server Project with Node.js](https://www.textcontrol.com/blog/2020/01/01/creating-a-websocket-server-project-with-nodejs/llms.txt)
- [Creating an Angular Document Editor Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-angular-document-editor-application/llms.txt)
- [ReportingCloud .NET Core Quickstart Tutorial](https://www.textcontrol.com/blog/2019/07/24/reportingcloud-dotnet-core-quickstart-tutorial/llms.txt)
- [Document Permissions and Password Encryption](https://www.textcontrol.com/blog/2019/07/05/document-permissions-and-password-encryption/llms.txt)
- [New Online Sample: Build your First Report](https://www.textcontrol.com/blog/2019/07/03/build-your-first-report/llms.txt)
- [Create your First Document with ReportingCloud](https://www.textcontrol.com/blog/2019/02/19/create-your-first-document-with-reportingcloud/llms.txt)
- [MailMerge: Starting Each Merge Block on a New Page](https://www.textcontrol.com/blog/2016/09/09/mailmerge-starting-each-merge-block-on-a-new-page/llms.txt)
- [Windows Forms and WPF: End a List on Return when Line is Empty](https://www.textcontrol.com/blog/2016/08/26/windows-forms-and-wpf-end-a-list-on-return-when-line-is-empty/llms.txt)
- [Using IFormattedText Objects to Access Elements Across All TextParts in a Document](https://www.textcontrol.com/blog/2016/08/25/using-iformattedtext-objects-to-access-elements-across-all-textparts-in-a-document/llms.txt)
