nested repeater

Discussion in 'ASP .Net' started by mark, Oct 13, 2005.

  1. mark

    mark Guest

    (not sure if this is the correct group)

    My problem is I need to have a "nested" repeater. I have an array which I
    load into a hashtable - that part works great. I can setup the second
    repeater to work just fine, as long as it's not nested within the first
    repeater. If it is nested within the first repeater, I don't get any data.
    If I put the second repeater as a separate repeater, not nested, it works
    fine.

    Here's my actual code, showing data pulled from the array within a loop:

    Dim arrRepeater As New ArrayList()
    'Repeat this part for each row
    x = 0
    Do Until x = db_fieldnamemax
    Dim htRepeater As New Hashtable()
    htRepeater.Add("ColName1", db_fieldname(x, 1))
    htRepeater.Add("ColName2", db_fieldname(x, 2))
    arrRepeater.Add(htRepeater)
    x += 1
    Loop
    Repeater1.DataSource = arrRepeater
    Repeater1.DataBind()


    Dim arrRepeater2 As New ArrayList()
    'Repeat this part for each row
    x = 0
    Do Until x = db_fieldproductmax
    Dim htRepeater As New Hashtable()
    htRepeater.Add("ColProduct1", db_fieldproduct(x, 1))
    htRepeater.Add("ColProduct2", db_fieldproduct(x, 2))
    arrRepeater.Add(htRepeater)
    x += 1
    Loop
    Repeater2.DataSource = arrRepeater2
    Repeater2.DataBind()

    Would someone please point me in the right direction on how to use a
    nested repeater??

    Here is my frontside code (where I think the problem is):

    <asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
    First item: <%#Container.DataItem("ColName1")%>
    Second item: <%#Container.DataItem("ColName2")%>
    <asp:Repeater ID="Repeater2" runat="server">
    <ItemTemplate>
    *** Nested item 1: <%#Container.DataItem("ColProduct1")%>
    *** Nested item 2: <%#Container.DataItem("ColProduct2")%>
    </ItemTemplate>
    </asp:Repeater>
    </ItemTemplate>
    </asp:Repeater>


    Also, the "Repeater2" shows undefined (in the code behind), unless we add
    the following
    statement in the code behind:

    Partial Class MainPage
    Inherits System.Web.UI.Page
    Dim Repeater2 As New System.Web.UI.WebControls.Repeater()

    -Mark
     
    mark, Oct 13, 2005
    #1
    1. Advertising

  2. you have to put the binding inside the first repeater's data bound event for
    the second repeater

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com



    "mark" wrote:

    > (not sure if this is the correct group)
    >
    > My problem is I need to have a "nested" repeater. I have an array which I
    > load into a hashtable - that part works great. I can setup the second
    > repeater to work just fine, as long as it's not nested within the first
    > repeater. If it is nested within the first repeater, I don't get any data.
    > If I put the second repeater as a separate repeater, not nested, it works
    > fine.
    >
    > Here's my actual code, showing data pulled from the array within a loop:
    >
    > Dim arrRepeater As New ArrayList()
    > 'Repeat this part for each row
    > x = 0
    > Do Until x = db_fieldnamemax
    > Dim htRepeater As New Hashtable()
    > htRepeater.Add("ColName1", db_fieldname(x, 1))
    > htRepeater.Add("ColName2", db_fieldname(x, 2))
    > arrRepeater.Add(htRepeater)
    > x += 1
    > Loop
    > Repeater1.DataSource = arrRepeater
    > Repeater1.DataBind()
    >
    >
    > Dim arrRepeater2 As New ArrayList()
    > 'Repeat this part for each row
    > x = 0
    > Do Until x = db_fieldproductmax
    > Dim htRepeater As New Hashtable()
    > htRepeater.Add("ColProduct1", db_fieldproduct(x, 1))
    > htRepeater.Add("ColProduct2", db_fieldproduct(x, 2))
    > arrRepeater.Add(htRepeater)
    > x += 1
    > Loop
    > Repeater2.DataSource = arrRepeater2
    > Repeater2.DataBind()
    >
    > Would someone please point me in the right direction on how to use a
    > nested repeater??
    >
    > Here is my frontside code (where I think the problem is):
    >
    > <asp:Repeater ID="Repeater1" runat="server">
    > <ItemTemplate>
    > First item: <%#Container.DataItem("ColName1")%>
    > Second item: <%#Container.DataItem("ColName2")%>
    > <asp:Repeater ID="Repeater2" runat="server">
    > <ItemTemplate>
    > *** Nested item 1: <%#Container.DataItem("ColProduct1")%>
    > *** Nested item 2: <%#Container.DataItem("ColProduct2")%>
    > </ItemTemplate>
    > </asp:Repeater>
    > </ItemTemplate>
    > </asp:Repeater>
    >
    >
    > Also, the "Repeater2" shows undefined (in the code behind), unless we add
    > the following
    > statement in the code behind:
    >
    > Partial Class MainPage
    > Inherits System.Web.UI.Page
    > Dim Repeater2 As New System.Web.UI.WebControls.Repeater()
    >
    > -Mark
    >
    >
    >
     
    =?Utf-8?B?Q3VydF9DIFtNVlBd?=, Oct 13, 2005
    #2
    1. Advertising

  3. mark

    Karl Seguin Guest

    Curt's suggestion is the best. If you need an example, check out:
    http://openmymind.net/index.aspx?documentId=8#7 (it also mentions an
    alternative, doing it inline).

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/
    "mark" <> wrote in message
    news:...
    > (not sure if this is the correct group)
    >
    > My problem is I need to have a "nested" repeater. I have an array which I
    > load into a hashtable - that part works great. I can setup the second
    > repeater to work just fine, as long as it's not nested within the first
    > repeater. If it is nested within the first repeater, I don't get any data.
    > If I put the second repeater as a separate repeater, not nested, it works
    > fine.
    >
    > Here's my actual code, showing data pulled from the array within a loop:
    >
    > Dim arrRepeater As New ArrayList()
    > 'Repeat this part for each row
    > x = 0
    > Do Until x = db_fieldnamemax
    > Dim htRepeater As New Hashtable()
    > htRepeater.Add("ColName1", db_fieldname(x, 1))
    > htRepeater.Add("ColName2", db_fieldname(x, 2))
    > arrRepeater.Add(htRepeater)
    > x += 1
    > Loop
    > Repeater1.DataSource = arrRepeater
    > Repeater1.DataBind()
    >
    >
    > Dim arrRepeater2 As New ArrayList()
    > 'Repeat this part for each row
    > x = 0
    > Do Until x = db_fieldproductmax
    > Dim htRepeater As New Hashtable()
    > htRepeater.Add("ColProduct1", db_fieldproduct(x, 1))
    > htRepeater.Add("ColProduct2", db_fieldproduct(x, 2))
    > arrRepeater.Add(htRepeater)
    > x += 1
    > Loop
    > Repeater2.DataSource = arrRepeater2
    > Repeater2.DataBind()
    >
    > Would someone please point me in the right direction on how to use a
    > nested repeater??
    >
    > Here is my frontside code (where I think the problem is):
    >
    > <asp:Repeater ID="Repeater1" runat="server">
    > <ItemTemplate>
    > First item: <%#Container.DataItem("ColName1")%>
    > Second item: <%#Container.DataItem("ColName2")%>
    > <asp:Repeater ID="Repeater2" runat="server">
    > <ItemTemplate>
    > *** Nested item 1: <%#Container.DataItem("ColProduct1")%>
    > *** Nested item 2: <%#Container.DataItem("ColProduct2")%>
    > </ItemTemplate>
    > </asp:Repeater>
    > </ItemTemplate>
    > </asp:Repeater>
    >
    >
    > Also, the "Repeater2" shows undefined (in the code behind), unless we add
    > the following
    > statement in the code behind:
    >
    > Partial Class MainPage
    > Inherits System.Web.UI.Page
    > Dim Repeater2 As New System.Web.UI.WebControls.Repeater()
    >
    > -Mark
    >
    >
     
    Karl Seguin, Oct 13, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    861
  2. Replies:
    0
    Views:
    2,885
  3. Replies:
    1
    Views:
    7,032
    Karl Seguin
    Aug 10, 2005
  4. uncensored
    Replies:
    0
    Views:
    818
    uncensored
    Oct 25, 2006
  5. Microsoft

    Repeater inside a Repeater

    Microsoft, Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    209
    Microsoft
    Aug 21, 2006
Loading...

Share This Page