[英]Nested Repeater Problems. ASP.Net C#
尽管我感到自己很亲密,但仍在努力使嵌套中继器正常工作!
我正在尝试创建两个嵌套的中继器,每个中继器都绑定到我创建的类列表。
我目前收到此错误消息:
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();
}
顶级中继器在未嵌套时与嵌套的中继器一样工作良好。
在嵌套转发器中:
<%# DataBinder.Eval(Container.DataItem, "[\"strTitle\"]")%>
该代码很可能是
<%# DataBinder.Eval(Container.DataItem, "strTitle")%>
没有更多的TR_BLL.Forum类知识,这是最可能的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.