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.
HeaderTemplate: This template is used for elements that you want to render once before your ItemTemplate section.
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.
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);
I'd recommend using the ListView. It implements a property called GroupCount.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With