Nested Repeaters in VB.NET RRS feed

  • Question

  • User-506894445 posted

    I've given up on my original dynamically-constructed poll page and am going with nested repeaters.

    I'm coming along pretty well, I just can't figure out how to populate the child repeater using a relation. All the really simple examples are in C#.

    This is what I'm going from:



     My code:

            Dim theDB As New db
            Dim query As String
            Dim QueSet As New DataSet
            Dim AnsSet As New DataSet
            Dim Ans As New DataSet

            Dim PollID As Integer = 1

            query = "SELECT * FROM [Questions] WHERE [PollID]=" & PollID
            QueSet = theDB.ExecuteOtherQuery(query)
            rptQuestion.DataSource = QueSet.Tables("Questions")

            query = "SELECT * FROM [MC_Answers] WHERE [PollID]=" & PollID & " AND [Questions.Order]=[MC_Answers.QuestionID]"
            AnsSet = theDB.ExecuteOtherQuery(query)
            AnsSet.Relations.Add("MyRelation", AnsSet.Tables("Questions").Columns("Order"), AnsSet.Tables("MC_Answers").Columns("QuestionID"))


    I don't really understand if I've got the above lines correct. 



    My asp:

             <asp:Repeater runat="server" id="rptQuestion">
                    <%#DataBinder.Eval(Container.DataItem, "QText_E")%><br />
                    <asp:Repeater runat="server" id="rptAnswer" datasource='<%# Ctype(Container.Dataitem,RepeaterItem).DataItem.GetChildRows("myrelation")%>'>
                             <%#DataBinder.Eval(Container.DataItem, "AText_E")%>

    My schema



    PollID               QText_E          QText_F            Type                 Order<o:p></o:p>


    <st1:Street w:st="on"><st1:address w:st="on">Order and PollID together serve as a primary key for the questions table. Thus, the MC_Answers table  has a many-to-one relationship with the Questions table.


    PollID               QuestionID         AText_E          AText_F            Order<o:p></o:p>

    <st1:Street w:st="on"><st1:address w:st="on">


    Monday, April 23, 2007 6:31 PM

All replies

  • User1815158493 posted

     Please help me with nested repeaters.

    im unable to find even a single proper working example..


    Thursday, August 27, 2009 12:00 AM
  • User2027633219 posted

    Here's my working code that took me a while to get right-

     Protected Sub GenerateProductCompatibility()
            Dim oConn = New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
            Dim manufacturerQueryStr = "SELECT distinct m.manufacturer_id, m.manufacturer_name FROM product_oem_xref x "
            manufacturerQueryStr += " JOIN manufacturers m ON m.manufacturer_id = x.manufacturer_id WHERE x.product_id = " + productId.ToString()
            Dim manufacturerAdapter = New SqlDataAdapter(manufacturerQueryStr, oConn)
            Dim ds = New DataSet()
            manufacturerAdapter.Fill(ds, "manufacturers")
            Dim modelQueryStr = "SELECT distinct manufacturer_id as manufacturer_id, model_number as model_number FROM product_oem_xref WHERE product_id = " + productId.ToString()
            Dim modelAdapter = New SqlDataAdapter(modelQueryStr, oConn)
            modelAdapter.Fill(ds, "product_oem_xref")
            ds.Relations.Add("relation1", ds.Tables("manufacturers").Columns("manufacturer_id"), ds.Tables("product_oem_xref").Columns("manufacturer_id"))
            ProductCompatibilityParent.DataSource = ds
        End Sub
     <asp:DataList ID="ProductCompatibilityParent" runat="server" RepeatColumns="5" RepeatDirection="Horizontal" >
                <b><%#Eval("manufacturer_name")%></b><br />
                <asp:DataList ID="ProductCompatibilityChild" datasource='<%# CType(Container.Dataitem,System.Data.DataRowView).Row.GetChildRows("relation1") %>' runat="server">
                        <%#DataBinder.Eval(Container.DataItem, "[""model_number""]")%>


    Saturday, January 30, 2010 3:21 AM