一起使用ListView和Repeater
我想将中继器放入中继器中。由于我的列表视图同时具有 ItemTemplate 和 AlternateItemTemplate,我是否需要添加两个中继器并绑定两个中继器?
<asp:ListView ID="lvData" runat="server" onitemdatabound="lvData_ItemDataBound">
<layouttemplate>
<div style="border:dotted 1px gray;">
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</div>
</layouttemplate>
<itemtemplate>
<div class="ListView">
<h5><%# Eval("CourseCode") %> - <%# Eval("CourseName") %></h5>
<asp:Repeater ID="rptComments" runat="server">
<ItemTemplate>
<p>
<%# DataBinder.Eval(Container.DataItem, "Comment") %></p>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblEmpty" Text="No comments to display..." runat="server" Visible='<%#bool.Parse((rptComments.Items.Count==0).ToString())%>'></asp:Label>
</FooterTemplate>
</asp:Repeater>
</div>
</itemtemplate>
<alternatingitemtemplate>
<div class="ListViewAlternate">
<h5><%# Eval("CourseCode") %> - <%# Eval("CourseName") %></h5>
<asp:Repeater ID="rptComments2" runat="server">
<ItemTemplate>
<p>
<%# DataBinder.Eval(Container.DataItem, "Comment") %></p>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblEmpty" Text="No comments to display..." runat="server" Visible='<%#bool.Parse((rptComments.Items.Count==0).ToString())%>'></asp:Label>
</FooterTemplate>
</asp:Repeater>
</div>
</alternatingitemtemplate>
<emptydatatemplate>
No records to display.
</emptydatatemplate>
</asp:ListView>
I would like to put Repeater inside a Repeater. Since my list view has both ItemTemplate and AlternateItemTemplate, do I need to add two repeaters and bind both repeaters?
<asp:ListView ID="lvData" runat="server" onitemdatabound="lvData_ItemDataBound">
<layouttemplate>
<div style="border:dotted 1px gray;">
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</div>
</layouttemplate>
<itemtemplate>
<div class="ListView">
<h5><%# Eval("CourseCode") %> - <%# Eval("CourseName") %></h5>
<asp:Repeater ID="rptComments" runat="server">
<ItemTemplate>
<p>
<%# DataBinder.Eval(Container.DataItem, "Comment") %></p>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblEmpty" Text="No comments to display..." runat="server" Visible='<%#bool.Parse((rptComments.Items.Count==0).ToString())%>'></asp:Label>
</FooterTemplate>
</asp:Repeater>
</div>
</itemtemplate>
<alternatingitemtemplate>
<div class="ListViewAlternate">
<h5><%# Eval("CourseCode") %> - <%# Eval("CourseName") %></h5>
<asp:Repeater ID="rptComments2" runat="server">
<ItemTemplate>
<p>
<%# DataBinder.Eval(Container.DataItem, "Comment") %></p>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblEmpty" Text="No comments to display..." runat="server" Visible='<%#bool.Parse((rptComments.Items.Count==0).ToString())%>'></asp:Label>
</FooterTemplate>
</asp:Repeater>
</div>
</alternatingitemtemplate>
<emptydatatemplate>
No records to display.
</emptydatatemplate>
</asp:ListView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定答案是肯定的。
或者,不要使用 AlternatingItemTemplate,而是在 ItemTemplate 内创建根据您自己的逻辑交替的标记。您基本上只需要使 div/@class 不同即可。
如果您可以以某种方式从 ItemTemplate 标记中检索项目的索引/位置,那么您可以使用简单的除以 2 来确定该项目是奇数还是偶数。
idx % 2 > 0
--> >奇怪的; else Evenodd:
Even
那么,当然,你只能有一个子中继器。
I'm pretty sure the answer is yes.
Alternatively, do not use AlternatingItemTemplate, but instead, within ItemTemplate create markup that alternates based on your own logic. You basically only need to make that div/@class different.
If you can somehow retrieve the index/position of the item, from within the ItemTemplate markup, then you can use a simple division by 2 to determine if the item is odd or even.
idx % 2 > 0
--> odd; else evenodd:
even
Then, of course, you can have only one child-repeater there.