Working with more than 2 nested repeater controls

Posted on 2006-04-10
Last Modified: 2008-01-09
Hi all,

I have successfully been able to use two asp:repeater controls on my page, however I am now trying to add a third repeater control and it's confusing me!

The example data output below is what I would like to have. At the moment I am displaying the Office and Departments fine. I now am trying to display the departments children which are Job Roles.

Office Name
    Department Name #1
        ¤ Chief Executive
        ¤ PA to Chief Guide
        ¤ PA to the Chief Executive
    Department Name #2
        ¤ Facilities Administrator
        ¤ Facilities Assistant
        ¤ Facilities Manager
        ¤ Facilities Technical Assistant
    Department Name #3
        ¤ Assistant Finance Officer
        ¤ Finance Officer
        ¤ Head of Finance & Business Development
        ¤ Management Accountant
        ¤ PA to Head of Finance
        ¤ Payment and Receipts Officer
    Department Name #4
        ¤ Head of Human Resources
        ¤ Human Resources Advisor
        ¤ Human Resources Co-ordinator
    Department Name #5
        ¤ Application Developer
        ¤ Business Systems Manager
        ¤ Database Administrator
        ¤ Development Manager
        ¤ I.T. Services Manager

My .aspx and .aspx.vb code are as follows ....

    <form id="Form1" method="post" runat="server">
        <br />

        <ASP:Repeater id="rptrOffices" runat="server">

                    <table width="100%" cellspacing="1" cellpadding="1" border="0" class="tableOrangeDisplay">
                                <th>Office / Department</th>
                                <th width="35">Action</th>

                  <td colspan="2"><strong><%#DataBinder.Eval(Container.DataItem, "Address1")%></strong></td>

            <asp:Repeater id="rptrDepartments" runat="server" datasource='<%# Container.DataItem.Row.GetChildRows("Office_Dept_Relationship") %>'>
                                  <td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<u><%#Container.DataItem("DepartmentName")%></u></td>

                <!--   < asp: Repeater id="rptrJobRoles" run at="server" datasource='??????????????????' > -->
                  <!--  < itemtemplate > -->
                                      <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - JOB ROLES HERE</td>
                                      <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - JOB ROLES HERE</td>
                                      <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - JOB ROLES HERE</td>
                  <!--  < /itemtemplate > -->
                <!--  < /asp: Repeater > -->






Imports System.Data
Imports System.Data.SqlClient

Partial Class system_jobRoles_Default
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim strSQL As String

        'Create Dataset
        Dim objDataSet As DataSet = New DataSet()

        'Create SQL connection
        Dim objConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("eLaunch").ConnectionString)

        'Populate command with 1st dataset
        Dim cmd1 As SqlDataAdapter = New SqlDataAdapter("SELECT DISTINCT O.[OfficesID], O.[address1] FROM [G_Tbl_Offices] O INNER JOIN [G_Tbl_Department] D ON O.[OfficesID] = D.[OfficesID] ORDER BY O.[Address1]", objConn)
        cmd1.Fill(objDataSet, "offices")

        'Populate command with 2nd dataset
        Dim cmd2 As SqlDataAdapter = New SqlDataAdapter("SELECT D.[DepartmentID], D.[DepartmentName], D.[OfficesID] FROM [G_Tbl_Department] D", objConn)
        cmd2.Fill(objDataSet, "departments")

        'Populate command with 3rd dataset
        strSQL = "SELECT       J.[JobRolesID], " & _
                 " J.[JobRole], " & _
                 " J.[Tbl_DepartmentID] " & _
                 "  FROM       [G_Tbl_JobRoles] J " & _
                 "      INNER JOIN [G_Tbl_Department] D ON J.[Tbl_DepartmentID] = D.[DepartmentID] " & _
                 "      INNER JOIN [G_Tbl_Offices] O ON D.[OfficesID] = O.[OfficesID] " & _
                 "  ORDER BY J.[JobRole]"

        Dim cmd3 As SqlDataAdapter = New SqlDataAdapter(strSQL, objConn)
        cmd3.Fill(objDataSet, "jobroles")

        'Assign parent / child columns for Office/Department relationship
        Dim Parent As DataColumn = objDataSet.Tables("offices").Columns("OfficesID")
        Dim Child As DataColumn = objDataSet.Tables("departments").Columns("OfficesID")
        Dim objRelation As DataRelation = New DataRelation("Office_Dept_Relationship", Parent, Child, False)

        'Assign parent / child columns for Department/Job Role relationship
        Parent = objDataSet.Tables("departments").Columns("DepartmentID")
        Child = objDataSet.Tables("jobroles").Columns("Tbl_DepartmentID")
        objRelation = New DataRelation("Dept_JobRole_Relationship", Parent, Child, False)

        'Assign repeater a datasource
        Me.rptrOffices.DataSource = objDataSet.Tables("offices")

        'Bind data to page

        'Clean up

    End Sub

End Class

So if anyone can help explain how I should go about displaying the Departments Job Roles I would be very thankful!

Question by:Guides
    LVL 39

    Expert Comment

    have you tried

    datasource='<%# Container.DataItem.Row.GetChildRows("Dept_JobRole_Relationship") %>'
    LVL 39

    Accepted Solution

    or this

    datasource='<%# Container.DataItem.GetChildRows("Dept_JobRole_Relationship") %>'

    Author Comment

    Hi Appari,

    Thanks for your help, your second suggestion has worked so I shall give you the full points. Much appreciated!

    Could you please explain why the datasource without ".Row." would work? What does .Row. do?

    Another quick question ... is the way I have suggested above the best solution in ASP.Net? I'm only new to this (have been doing classic ASP for years!) and would like some feedback.

    In classic ASP I did the following which seems easier with the one SQL statement ... See below ...

    SELECT       J.[JobRolesID],
    FROM       [G_Tbl_JobRoles] J
          INNER JOIN [G_Tbl_Department] D ON J.[Tbl_DepartmentID] = D.[DepartmentID]
          INNER JOIN [G_Tbl_Offices] O ON D.[OfficesID] = O.[OfficesID]
    ORDER BY O.[Code],


                '0 J.[JobRolesID],
                '1 J.[JobRole],
                '2 J.[Description],
                '3 J.[Tbl_DepartmentID],
                '4 D.[DepartmentName],
                '5 D.[OfficesID],
                '6 O.[Code]
                if isArray(arrAllJobRoles) then
                      <table width="100%" cellspacing="1" cellpadding="1" border="0" class="tableOrangeDisplay">
                                  <th>Department / Job Role</th>
                                  <th width="40">Action</th>
                      for i = LBound(arrAllJobRoles, 2) To UBound(arrAllJobRoles, 2)

                            if (lngPreviousOfficeID <> arrAllJobRoles(5, i)) then
                                  <td colspan="2" bgcolor="#F8F8F8"><strong><%=Ucase(arrAllJobRoles(6, i))%></strong></td>
                            end if

                            if (lngPreviousDepartmentID <> arrAllJobRoles(3, i)) then
                                  <td colspan="2">&nbsp; &nbsp; <u><%=arrAllJobRoles(4, i)%></u></td>
                            end if
                                  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &curren; <%=arrAllJobRoles(1, i)%></td>
                                  <td align="right"><a href="#" onclick="'edit.asp?JobRoleID=<%=arrAllJobRoles(0, i)%>','detailedContent');"><img src="/system/com/img/edit.gif" width="16" height="16" alt="Edit"></a></td>
                            lngPreviousDepartmentID = arrAllJobRoles(3, i)
                            lngPreviousOfficeID     = arrAllJobRoles(5, i)
                end if

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now