0

Struggling to get nested repeaters working although I feel I am close!

I am trying to create two nested repeaters each bound to a list of classes I created.

I am currently getting this error message:

DataBinding: 'TR_BLL.Forum' does not allow indexed access.

This is the code of the page:

<!-- Forum Group Repeater -->
<asp:Repeater ID="rptForumGroups" runat="server" OnItemDataBound="rptForumGroups_ItemDataBound">
    <ItemTemplate>
        <div class="content">
            <div class="content-header">
                <h3><%# DataBinder.Eval(Container.DataItem, "strName")%></h3>
            </div>

            <!-- Forum Repeater -->
            <asp:Repeater ID="rptForums" runat=server>
                <ItemTemplate>
                    <%# DataBinder.Eval(Container.DataItem, "[\"strTitle\"]")%>
                </ItemTemplate>
            </asp:Repeater>
            <!-- End Forum Repeater -->

        </div>
    </ItemTemplate>    
</asp:Repeater>
<!-- End Forum Group Repeater -->

And this is the code behind:

        protected void Page_Load(object sender, EventArgs e)
    {
        // Bind Forum Groups
        TR_BLL.ForumGroups ForumGroups = new TR_BLL.ForumGroups();
        List<TR_BLL.ForumGroup> listForumGroups = new List<TR_BLL.ForumGroup>();
        listForumGroups = ForumGroups.GetAllForumGroups();
        rptForumGroups.DataSource = listForumGroups;
        rptForumGroups.DataBind();
    }

    protected void rptForumGroups_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        // Bind Forums
        TR_BLL.Forums Forums = new TR_BLL.Forums();
        List<TR_BLL.Forum> listForums = new List<TR_BLL.Forum>();
        listForums = Forums.GetAllForums();

        Repeater rptForums = (Repeater)e.Item.FindControl("rptForums");
        rptForums.DataSource = listForums;
        rptForums.DataBind();
    }

The top level repeater works fine as does the nested one when it is not nested.

2
  • 1
    Why is the Eval statement in the nested repeater using "[\"strTitle\"]" instead of "strTitle". The issue looks like it is with the TR_BLL.Forum class, can you post that? Commented Feb 17, 2012 at 19:11
  • Doh! I used "[\"strTitle\"]" because my initial solution used two data tables. It works with "strTitle" If you put a response I will mark it as the answer. Thanks! Commented Feb 17, 2012 at 19:15

1 Answer 1

2

Within the nested repeater:

<%# DataBinder.Eval(Container.DataItem, "[\"strTitle\"]")%>

The code should most likely be

<%# DataBinder.Eval(Container.DataItem, "strTitle")%>

Without more knowledge of the TR_BLL.Forum class this is the most likely cause.

Sign up to request clarification or add additional context in comments.

1 Comment

In my case, I was using ["Date"], the brackets needed to be removed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.