2012-02-17 24 views
0

私は近くにいると感じていますが、ネストされたリピータを動作させるのに苦労しています!ネストされたリピータの問題。 ASP.Net C#

作成したクラスのリストにそれぞれバインドされた2つのネストされたリピーターを作成しようとしています。

私は現在、このエラーメッセージを取得しています:

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(); 
    } 

トップ入れ子になっていない場合は、入れ子になっているものと同じように、高レベルのリピータも正常に動作します。

+1

ネストされたリピータのEval文は、なぜなら、 "" strTitle "の代わりに[\" strTitle \ "]" "を使用しています。問題はTR_BLL.Forumクラスのように見えますが、投稿できますか? –

+0

Doh!私の初期のソリューションは2つのデータテーブルを使用していたので、 "[\" strTitle \ "]"を使用しました。 "strTitle"と一緒に使用します 回答を記入すると答えとしてマークします。ありがとう! –

答えて

2

ネストされたリピータの中で:

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

コードは、ほとんどの場合、これが最も可能性の高い原因であるTR_BLL.Forumクラスのより多くの知識がなければ

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

でなければなりません。

+1

私の場合、["日付"]を使用していましたが、括弧を削除する必要がありました。 –

関連する問題