In this tutorial, we will demostrate how to use nested Repeater control to display hierarchical data using ASP.NET 2.0 and C#. You can apply this usage to the other data binding controls as well. For instance, to let DataGrid nest DataGrid, DataList nest DataList etc.

The Repeater Web server control is a container control that allows you to create custom lists out of any data that is available to the page. The Repeater control does not have a built-in rendering of its own, which means that you must provide the layout for the Repeater control by creating templates. When the page runs, the Repeater control loops through the records in the data source and renders an item for each record. First, import the System.Data.SqlClient namespace. The System.Data.SqlClient namespace is the.NET Framework Data Provider for SQL Server. The.NET Framework Data Provider for SQL Server describes a collection of classes used to access a SQL Server database in the managed space.

Then, add a new web form to the solution, name it Nestedrepeater.aspx, and create a connection to the sample database pubs. Binding the table of Authors to Repeater Control.

In the Page_Load, add the child table data binding, and create relationship between the tables of author and title.

The front Nestedrepeater .aspx page looks something like this:

The flow for the code behind page is as follows.

Download Source Files