Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

DataGrid and Nested DataList Master/Child Relation - Please Help

Posted on 2005-05-16
4
Medium Priority
?
414 Views
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"
     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.
0
Comment
Question by:-Hakan-
2 Comments
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 2000 total points
ID: 14015219
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
 
LVL 9

Expert Comment

by:BurntSky
ID: 14015294
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Screencast - Getting to Know the Pipeline
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

578 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