[英]Nested Repeater Problems. ASP.Net C#
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. 顶级中继器在未嵌套时与嵌套的中继器一样工作良好。
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. 没有更多的TR_BLL.Forum类知识,这是最可能的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.