Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested Repeater

Tags:

c#

asp.net

I Have a display that needs to be a little more dynamic than what I'm use to and can't seem to quite find the answer I need.

                        Customer a     Customer b     Customer c    (and so on)
  savings with product a

  savings with product b

  (and so on)

I know there will always be a minimum of one in each field. Someone said use a nested repeater or something. I looked around and couldn't find out how to use a nested repeater. I am on a deadline and can't really play with things until I find something that works.

What asp control should I use to do this? An example would be nice but I just need help in the right direction.

I am using sql but getting the data through link. The data ends up in lists.

Thank you for your help!

like image 735
Hazior Avatar asked Jul 28 '10 18:07

Hazior


1 Answers

Nested Repeaters are pretty easy. Just throw one in your ItemTemplate, and in the OnItemDataBound event of your main repeater do the following

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
     DataRowView row = (DataRowView)e.Item.DataItem;

     Repeater nestedRepeater = e.Item.FindControl("NestedRepeater") as Repeater;
     nestedRepeater.DataSource = getSavingsPerCustomer(row["customerID"]);
     nestedRepeater.DataBind();
 }

Where the template of the outer repeater had a customer name and a repeater and the inner one has the different savings

probably incorrect syntax but you get the idea

<asp:repeater ID="outer">
<HeaderTemplate>
    <div style="float:left">
</HeaderTemplate>
<ItemTemplate>
     Customer: <%= Eval(customer)%><br/>
     <asp:repeater ID="NestedRepeater">
          <ItemTemplate>
          Saving: <%= Eval(saving)%><br/>
          </ItemTemplate>
     </asp:repeater>
</ItemTemplate>
<FooterTemplate>
    </div>
</FooterTemplate>
</asp:repeater>

Similar SO question: Repeater in Repeater

like image 79
jumpdart Avatar answered Sep 23 '22 01:09

jumpdart