开发者

is it wrong to use a repeater within a repeater?

I have a list of parents, that have children. I am trying to output this on my website doing the following. It works, but is it right? What is the best alternative?

 <ul id="example">
        <asp:Repeater ID="monkey" runat="server" >

        <ItemTemplate>
            <li>
                <span class="folder">
                  <%# GetPlantName((string)Container.DataItem) %>
                </span>

                <ul>
                  <asp:Repeater id="moo" runat="server" DataSource="<%# GetTagList((string)Container.DataItem) %>">
                        <ItemTemplate>
                            <li>
                                <asp:LinkButton ID="d" runat="server" Text='<%# Eval("ReportNo")%>'></asp:LinkButton>                  
                            </li>
                        </ItemTemplate>    
                  </asp:Repeater>
                </ul>      
            </li>        
        </ItemTempla开发者_高级运维te>
        </asp:Repeater>
    </ul>


Nested repeaters are acceptable. Just be careful with things like RowDataBound events. It's not always obvious, especially to junior developers, that these methods are essentially nested loops. I've seen mistakes like a trip to the database in the nested repeater, which results in a lot of overhead.

Just keep in mind that what you're doing is essentially a nested loop and design code accordingly and it's perfectly fine.


I hope no

I have a repeater in a repeater in a repeater in a repeater in something :-p


No, it is not wrong! On the contrary, it is what we have to do more often than not.

Sometimes there are better solutions but that always depends on the requirements.

hth,

\ ^ / i l l


I see nothing wrong here at all. You have a list (repeater 1) with a nested list (repeater 2).


Is it wrong? No. It's only 'wrong' (and that's basically a pseudonym for inefficient) if you plan on doing something with a repeater that could be done easier with something else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜