Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to separate the repeater data by number of items

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.

like image 829
Jronny Avatar asked Mar 29 '10 09:03

Jronny


People also ask

Which template is a much when displaying the data in a Repeater control?

HeaderTemplate: This template is used for elements that you want to render once before your ItemTemplate section.

What is a Repeater control?

The Repeater control allows you to split markup tags across the templates. To create a table using templates, include the begin table tag ( <table> ) in the HeaderTemplate, a single table row tag ( <tr> ) in the ItemTemplate, and the end table tag ( </table> ) in the FooterTemplate.


2 Answers

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);
like image 79
Fabian Avatar answered Sep 17 '22 19:09

Fabian


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

like image 39
citronas Avatar answered Sep 17 '22 19:09

citronas