views:

46

answers:

2

For example, we have 19 items on the repeater datasource. And we wanted to separate them using
by 5 items.

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? Thanks.

+5  A: 

Create a seperator template like so

<SeperatorTemplate><br /></SeperatorTemplate>

Then you have to bind ItemDataBound event before you call DataBind() on the repeater. In this event you look at the item count and display seperator when you can divide the item count by 5, like so:

if (e.Item.ItemType == ListItemType.Seperator)
  e.Item.Visible = ((e.Item.Parent as Repeater).Items.Count % 5 == 0);
Fabian
Thanks. I have also tried <%#CreateSeparator(DataBinder.Eval(Container, "ItemIndex", ""))%> call to a function on the code-behind and it also works. But which is faster?
Jronny
A: 

I'd recommend using the ListView. It implements a property called GroupCount.

citronas