ASP.net Repeater:嵌套布局的最佳实践
基本上,我要求最好的方法来执行以下操作: 我有这样的布局
<div class="outer">
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
</div>
<div class="outer">
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
</div>
<div class="outer">
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
</div>
所以,外部 div 将重复 3 次,每个内部 div 重复四次。我在 ASP.net 中执行此操作,信息来自数据库(可能通过 Linq)...
我问使用嵌套的中继器和勺子通过 for/ 一次为每个中继器提供四条记录是否更好foreach 循环,或将外部 div 作为文字输出?
编辑
<asp:Repeater ID="MyOuterRepeater" runat="server">
<ItemTemplate>
<div class="outer">
<asp:Repeater ID="MyInnerRepeater" runat="server">
<ItemTemplate>
<div class="inner">
<!-- content -->
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</ItemTemplate>
</asp:Repeater>
或者只是有一个,在顶部和底部带有开始/结束文字,使它们仅在需要时可见?
编辑:有没有人有一个如何完成的例子^^^
Basically, I'm asking for the best way to do the following:
I have a layout like this
<div class="outer">
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
</div>
<div class="outer">
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
</div>
<div class="outer">
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
<div class="inner"><!-- content --></div>
</div>
So, the outer div is to be repeated three times, with each inner div repeated four times. I'm doing this in ASP.net, the information is coming from a database (probably through Linq)...
I am asking is it better to use a nested repeater and spoon feed each repeater four records at a time through a for/foreach loop, or output the outer divs as literals?
EDITED
<asp:Repeater ID="MyOuterRepeater" runat="server">
<ItemTemplate>
<div class="outer">
<asp:Repeater ID="MyInnerRepeater" runat="server">
<ItemTemplate>
<div class="inner">
<!-- content -->
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</ItemTemplate>
</asp:Repeater>
Or just have one, with opening/ending literals at the top and bottom, making them visible only when needed?
EDIT: Does anybody have an example how it would be done^^^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的转发器定义不会创建您在问题中提供的结果 HTML。它实际上应该是:
否则你的
outer div
只会渲染一次,并且所有inner
div
都将被包含在同一个外部div
中。嵌套中继器?
如果您的
inner
元素是动态的,具体取决于数据,您当然应该使用嵌套的重复器,但如果每个outer
将包含四个inner
,那么我没有看到嵌套中继器有任何好处。它实际上会执行得更慢并且消耗更多的资源。那是你不想要的,是吗?Your repeater definition will not create resulting HTML that you also provided in your question. It should actually be:
Otherwise your
outer div
will only be rendered once and allinner
div
s will be contained in the same outerdiv
.Nesting repeaters?
If your
inner
elements are dynamic depending on data, you should of course use nested repeaters, but if everyouter
will contain fourinner
, then I don't see any benefit in having nested repeaters. It will actually execute slower and consume more resources. And that's something you don't want, do you?