0

I have a repeater inside another. Like so :

<asp:Repeater ID="CategoryRepeater" runat="server" OnItemDataBound="ItemBound">
    <ItemTemplate>
        <div class="groupbox">
            <fieldset>
                <legend><%# Container.DataItem %></legend>
                <table>
                    <asp:Repeater ID="ItemRepeater" runat="server">
                    <ItemTemplate>
                        <tr>
                        <td>
                            <asp:CheckBox id="chkItem" runat="server" Text='<%# Eval("Text")%>' />  
                            <asp:Button ID="btnXRefs" Text="x-refs" runat="server" CssClass="xRefButton" OnClick="btnSelectXRefs_Click" />
                        </td>
                        </tr>
                    </ItemTemplate>
                    </asp:Repeater>
                </table>
            </fieldset>
        </div>
    </ItemTemplate>
</asp:Repeater>

CODE BEHIND :

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            using (var db = new DbContext())
            {
                CategoryRepeater.DataSource = db.Categories.OrderBy(x => x.Heading).Select(x => x.Heading).Distinct();
                CategoryRepeater.DataBind();
            }
        }
    }

    protected void ItemBound(object sender, RepeaterItemEventArgs args)
    {
        if (args.Item.ItemType == ListItemType.Item)
        {
            Repeater childRepeater = (Repeater)args.Item.FindControl("ItemRepeater");
            var item = args.Item as RepeaterItem;
            using (var db = new DbContext())
            {
                childRepeater.DataSource = db.Categories.Where(x => x.Heading == item.DataItem).OrderBy(x => x.Text);
                childRepeater.DataBind();
            }
        }
    }

My goal is to first make many groupboxes using the top level, then bind items into each one. So I end up with many small stacked lists of checkboxes.

Problem is, all the top level boxes appear, yet only the first one contains checkbox items, ie. only the first one is bound internally, and the ItemBound method is only called once for the first one.

Any ideas why?

sprocket12
  • 5,368
  • 18
  • 64
  • 133
  • Sorry that was a mistake in my code, I originally did try OnItemDataBound as per this Q -- http://stackoverflow.com/questions/2923137/repeater-in-repeater (antons answer) – sprocket12 Nov 21 '12 at 10:33
  • How are you binding this thing ? can you share your binding code plz. – yogi Nov 21 '12 at 10:40
  • @yogi posted full code behind linked to this. – sprocket12 Nov 21 '12 at 10:43
  • How many items does your `CategoryRepeater` have ? – yogi Nov 21 '12 at 10:50
  • Only 2 at the moment. 1st one has 2 sub items, 2nd one 4. But the 2nd one shows none as I dont think its bound properly. Just the top level name shows because of the first binding. – sprocket12 Nov 21 '12 at 11:07

1 Answers1

0

This line

if (args.Item.ItemType == ListItemType.Item)

Should be like this

if(args.Item.ItemType = ListItemType.Item || 
   args.Item.ItemType == ListItemType.AlternatingItem)
yogi
  • 19,175
  • 13
  • 62
  • 92