DataGrid and Nested DataList Master/Child Relation - Please Help

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"
     Width="754"
     CellPadding="3"
     CellSpacing="0"
     GridLines="None"
     DataKeyField="ID"
     ShowHeader="False"
     ShowFooter="False"
     AutoGenerateColumns="False">
     <Columns>
          <asp:TemplateColumn ItemStyle-Height="150px" HeaderText="Thumbnail" ItemStyle-HorizontalAlign="Center" >
               <ItemTemplate>
                    <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>
                              <div class="plAdminPropHeader">
                                   <a href='editProperty.aspx?PropID=<%# DataBinder.Eval(Container.DataItem, "Id") %>'>Edit Property</a>
                                   &nbsp;/&nbsp;
                                   <a href="#">Edit Images</a>
                                   &nbsp;/&nbsp;
                                   <a href='editPDFs.aspx?PropID=<%# DataBinder.Eval(Container.DataItem, "Id") %>'>Edit PDFs</a>
                              </div>
                         </div>
                         <div>
                              <img style="float : left; border : 1px solid #999;" width="100px" height="100px" src='../ListingImages/<%# DataBinder.Eval(Container.DataItem, "ListingThumbNail") %>' />
                         </div>
                         <div class="plAdminDesc">
                              <%# DataBinder.Eval(Container.DataItem, "ListingDesc") %>
                         </div>
                         <div style="border : 2px solid red;">
                              <asp:DataList ID="dgListingPDFs"
                                   DataSource='<%# Container.DataItem.Row.GetChildRows("MyRelation") %>'
                                   Runat="server">
                                   <ItemTemplate>
                                        <%# DataBinder.Eval(Container.DataItem, "Description") %>
                                   </ItemTemplate>
                              </asp:DataList>
                         </div>
                    </div>
               </ItemTemplate>
          </asp:TemplateColumn>
     </Columns>
</asp:DataGrid>
==================================



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
        'Next

        dgEditListings.DataSource = DS.Tables("Listings").DefaultView
        dgEditListings.DataBind()
    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.
-Hakan-Asked:
Who is Participating?
 
Jeff CertainCommented:
How about... taking the easy way out and using the HierarGrid control ;)

It's available at http://denisbauer.com/ASPNETControls/HierarGrid.aspx

You'd just make your child template control contain a datalist instead of the more typical datagrid...
0
 
BurntSkyCommented:
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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.