简体   繁体   English

显示对象列表中的层次结构数据

[英]Display hierarchal data from list of objects

I have a list of objects that I want to display in a particular way, and am having way more trouble than I was expecting. 我有一个要以特定方式显示的对象列表,并且遇到的麻烦比我预期的要多。 Essentially I need a setup as follows: 本质上,我需要如下设置:

  • Parent Level 2 (header) 家长2级(标题)
  • Child Level 3 items in a table 表格中的第3级儿童

This repeats until the end of the list that gets pulled on each pageload. 重复此过程,直到在每次页面加载时提取列表的末尾。 I've taken a try at nested repeaters but failed. 我尝试过嵌套中继器,但失败了。

<asp:Repeater runat="server" ID="parentMeetingRepeater" >
<ItemTemplate>
    <h5><%# GetParentMeetingName(Eval("Id")) %></h5>
    <hr />

    <asp:Repeater runat="server" ID="childMeetingRepeater" >
        <HeaderTemplate>
            <table style="width: 100%;">
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <a href="/Display.aspx?ccbid=<%# Eval("Id")%>"><%# Eval("Name") %></a>
                </td>
                <td>
                    <%# Eval("Description") %>
                </td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
</ItemTemplate>                       

There was an event on the parent repeater to databind the 2nd repeater, but I quickly realized theres no logic to tell it to only display level 3 items with a parent of the level2 id. 父级中继器上发生了一个事件,要对第二个中继器进行数据绑定,但是我很快意识到没有逻辑告诉它仅显示具有父级为2的ID的级别3项。 Any ideas how I might be able to attack this? 有什么想法可以解决这个问题吗? I'm thinking nested repeaters might be the wrong direction. 我认为嵌套中继器可能是错误的方向。 - Thanks - 谢谢

After getting some advice, I ended up using a listview instead. 得到一些建议后,我最终改用了列表视图。 The correct binding with a list of data objects and the nested repeaters was driving me mental so this is a much cleaner route. 与数据对象列表和嵌套转发器的正确​​绑定使我感到不安,因此这是一条更简洁的方法。

               <asp:ListView ID="uxTaxonomies" runat="server" ItemPlaceholderID="itemPlaceholder">
                    <LayoutTemplate>
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                    </LayoutTemplate>
                    <ItemTemplate>
                        <h5><%#((TaxonomyData)Container.DataItem).Name %></h5>
                        <hr/>
                        <asp:ListView ID="uxTaxChildren" runat="server" ItemPlaceholderID="itemPlaceholder" DataSource="<%#((TaxonomyData)Container.DataItem).Taxonomy %>">
                            <LayoutTemplate>
                                <table class="noBorder">
                                    <tbody>
                                        <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                                    </tbody>
                                </table>
                            </LayoutTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td><a href="/MeetingDisplay.aspx?ccbid=<%#((TaxonomyData)Container.DataItem).Id %>"><%#((TaxonomyData)Container.DataItem).Name %></a>  </td>
                                    <td><%#((TaxonomyData)Container.DataItem).Description %></td>
                                </tr>
                            </ItemTemplate>
                        </asp:ListView>
                    </ItemTemplate>
                </asp:ListView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM