DataGrid and Nested DataList Master/Child Relation - Please Help

Posted on 2005-05-16
Last Modified: 2010-08-05
Ok... basically I want to have my main DataGrid displaying a list of Properties (i.e. Real Estate) and my nested datalist to show .PDFs associated to those properties... I've read about 15-20 examples on how to do this and most follow a very similar path... However my implementation doesn't work haha... So I'm going to post my .aspx code... and my code behind... and if anyone has an idea of whats wrong I'll be willing to post anything anyone needs lol...

DataGrid from .aspx page
<asp:DataGrid ID="dgEditListings" Runat="server"
          <asp:TemplateColumn ItemStyle-Height="150px" HeaderText="Thumbnail" ItemStyle-HorizontalAlign="Center" >
                    <div align="center">
                         <div style="width : 746px; margin-top : 4px; margin-bottom : 4px; padding-left : 4px; padding-right : 4px; font-size : 14px; font-weight : bold; border : 1px dashed #999; color : #666666; background-color : #D0DAF4; height : 18px;">
                              <div style="float : left;">
                                   <%# DataBinder.Eval(Container.DataItem, "ListingName") %>
                              <div class="plAdminPropHeader">
                                   <a href='editProperty.aspx?PropID=<%# DataBinder.Eval(Container.DataItem, "Id") %>'>Edit Property</a>
                                   <a href="#">Edit Images</a>
                                   <a href='editPDFs.aspx?PropID=<%# DataBinder.Eval(Container.DataItem, "Id") %>'>Edit PDFs</a>
                              <img style="float : left; border : 1px solid #999;" width="100px" height="100px" src='../ListingImages/<%# DataBinder.Eval(Container.DataItem, "ListingThumbNail") %>' />
                         <div class="plAdminDesc">
                              <%# DataBinder.Eval(Container.DataItem, "ListingDesc") %>
                         <div style="border : 2px solid red;">
                              <asp:DataList ID="dgListingPDFs"
                                   DataSource='<%# Container.DataItem.Row.GetChildRows("MyRelation") %>'
                                        <%# DataBinder.Eval(Container.DataItem, "Description") %>

Code Behind - The Sub thats supposed to make it happen
    Private Sub GetListingsAndPDFs()
        Dim DS As New DataSet
        Dim MyConnection As SqlConnection
        Dim MyDataAdapter1 As SqlDataAdapter
        Dim MyDataAdapter2 As SqlDataAdapter

        Dim drParent As DataRow
        Dim drChild As DataRow

        'Create a connection to the SQL Server.
        MyConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))

        'Create a DataAdapter, and then provide the name of the stored procedure.
        MyDataAdapter1 = New SqlDataAdapter("spGetListings", MyConnection)
        MyDataAdapter1.SelectCommand.CommandType = CommandType.StoredProcedure
        MyDataAdapter1.Fill(DS, "Listings")

        'Create a DataAdapter, and then provide the name of the stored procedure.
        MyDataAdapter2 = New SqlDataAdapter("spGetListingsPDFs", MyConnection)
        MyDataAdapter2.SelectCommand.CommandType = CommandType.StoredProcedure
        MyDataAdapter2.SelectCommand.Parameters.Add(New SqlParameter("@PropID", SqlDbType.Int, 4))
        MyDataAdapter2.SelectCommand.Parameters("@PropID").Value = 0
        MyDataAdapter2.Fill(DS, "ListingPDFs")

        DS.Relations.Add("MyRelation", DS.Tables("Listings").Columns("ID"), DS.Tables("ListingPDFs").Columns("ListingID"))

        'For Each drParent In DS.Tables("Listings").Rows
        '    lblOutput.Text &= "<h3>" & drParent("ListingName") & "</h3>"
        '    For Each drChild In drParent.GetChildRows("MyRelation")
        '        lblOutput.Text &= "<li>" & drChild("Description")
        '    Next

        dgEditListings.DataSource = DS.Tables("Listings").DefaultView
    End Sub

One thing to point out... You will notice that I have a set of For/Next Loops towards the bottom of my Sub on the code behind page... I put that in there for testing purposes to see if my relation in code was correct... It looks fine to me but i will post the result of commenting out the DataGrid Bind and uncommenting the For/Next Loops...

DataGrid Commented - For/Next Uncommented
Brantley Commons
  Desc Brochure
  Desc Demographics
  Desc Site Plan
  Desc Floor Plan
  Desc Elevations

Colonial Center
  Desc Brochure
  Desc Demographics
  Desc Site Plan
  Desc Floor Plan
  Desc Elevations

Crystal Place
  Desc Brochure
  Desc Demographics
  Desc Site Plan
  Desc Floor Plan
  Desc Elevations

World Plaza Lane
  Desc Brochure
  Desc Demographics
  Desc Site Plan
  Desc Floor Plan
  Desc Elevations

All help is greatly appreciated...

Kind Regards,
Hakan A.
Question by:-Hakan-
    LVL 24

    Accepted Solution

    How about... taking the easy way out and using the HierarGrid control ;)

    It's available at

    You'd just make your child template control contain a datalist instead of the more typical datagrid...
    LVL 9

    Expert Comment

    When you say your implementation doesn't work...what exactly do you mean?  Does it throw an error?  Does the DataGrid bind correctly, but not the DataList?  Does nothing show up at all? ...?  My guess is the DataList just doesn't show up because it's not being bound correctly.

    Personally, I'd create an EventHandler for the DataGrid's ItemCreated event, find the DataList and bind it there.

    You said you've read 15-20 examples of this; could you post a few links?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now