尽管我觉得我很亲密但仍然努力让嵌套的中继器工作!
我正在尝试创建两个嵌套的转发器,每个转发器都绑定到我创建的类列表。
我目前收到此错误消息:
DataBinding: 'TR_BLL.Forum' does not allow indexed access.
这是页面的代码:
<!-- 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 -->
这就是背后的代码:
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();
}
顶层转发器工作正常,嵌套转发器没有嵌套。
答案 0 :(得分:2)
在嵌套转发器中:
<%# DataBinder.Eval(Container.DataItem, "[\"strTitle\"]")%>
代码很可能是
<%# DataBinder.Eval(Container.DataItem, "strTitle")%>
如果不了解TR_BLL.Forum类,这是最可能的原因。