Get repeater item count

Zbyněk Nedoma asked on August 24, 2018 12:14

Hi, I have repeater at my page to display articles and I would like to get number of repeater items and display it outside of this web part. For example above the repeater. I know, that inside repeater transformations I can use DataItemCount.

Is this possible?

Thanks, Zbynek

Correct Answer

Brenden Kehren answered on August 24, 2018 21:16

Easiest, non-programming trick I've found to do is hook the repeater up to a universal pager. Then use the pager's Genearal-PagerLayout transformation (in the Pager transformations page type) to get that count.

You'll have to create some dummy transformations for the other items but pretty easy to do.

This will be what you're eventually looking for:

<%# Eval("Items")%>

2 votesVote for this answer Unmark Correct answer

Recent Answers


Arun Kumar answered on August 24, 2018 14:45

Check this post, you might need to clone the repeater web part and then override its method to get the count and display it in control on the page.

0 votesVote for this answer Mark as a Correct answer

Dragoljub Ilic answered on August 24, 2018 16:32 (last edited on August 24, 2018 16:33)

Hi,

You can move all code for retrieving pages into one 'Pages data source' and then use two repeaters on the page. Both will hit same pages data source, but one of them will be 'dummy' repeater which will have transformation only for number of items in repeater like this: {% DataItemCount %}, while another will contain everything for showing list of articles.

You can also create custom macro where you will use DocumentApi to retreive all pages (with same configuration as datasource) and then just show number of them on the site, something like this:

var pages = DocumentHelper.GetDocuments("CMS.Articles")
                                .Path("/Articles/", PathTypeEnum.Children)
                                .OnSite("CorporateSite")
                                .Culture("en-us")
                                .Published();

Best regards, Dragoljub

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.