简体   繁体   English

如何按项目数分隔转发器数据

[英]How to separate the repeater data by number of items

For example, we have 19 items on the repeater datasource. 例如,我们在转发器数据源上有19个项目。 And we wanted to separate them using 我们想用它们分开它们
by 5 items. 共5项。

It's like 就像是

01 02 03 04 05 <br />
06 07 08 09 10 <br />
11 12 13 14 15 <br />
16 17 18 19

How are we going to do this in asp.net repeater? 我们如何在asp.net转发器中执行此操作? Thanks. 谢谢。

Create a seperator template like so 像这样创建一个分隔符模板

<SeperatorTemplate><br /></SeperatorTemplate>

Then you have to bind ItemDataBound event before you call DataBind() on the repeater. 然后,您必须在转发器上调用DataBind()之前绑定ItemDataBound事件。 In this event you look at the item count and display seperator when you can divide the item count by 5, like so: 在这种情况下,当您可以将项目计数除以5时,您会查看项目计数并显示分隔符,如下所示:

if (e.Item.ItemType == ListItemType.Seperator)
  e.Item.Visible = ((e.Item.Parent as Repeater).Items.Count % 5 == 0);

I'd recommend using the ListView. 我建议使用ListView。 It implements a property called GroupCount. 它实现了一个名为GroupCount的属性。

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

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