Hi,
the easiest way how to count items in repeater is in transformation using following macro:
<%# DataRowView.DataView.Count %>If you would like to count repater items in code behind of webpart you can do it following way:
1. Create a clone of CMSrepeater webpart and modify a content of cloned webpart as discribed in this
article2. Please add
repItems.DataBind(); to
public override void OnContentLoaded() method
3. Now in your aspx.cs teplate create a repeater instance:
public partial class CMSTemplates_CorporateSiteAspx_temp : TemplatePage
{
protected void Page_Load(object sender, EventArgs e)
{
// Create an instance of cloned web part
CMSWebParts_Viewers_Documents_cmsrepeateritem repeater = Page.LoadControl("~/CMSWebParts/Viewers/Documents/cmsrepeateritem.ascx") as CMSWebParts_Viewers_Documents_cmsrepeateritem;
repeater.Path="Events/%";
repeater.TransformationName="cms.bookingevent.preview";
repeater.ClassNames="cms.bookingevent";
// Display repater in Panel control
panel.Controls.Add(repeater);
panel.DataBind();
}
}
4. Your aspx file should look like this one:
<%@ Page Title="" Language="C#" MasterPageFile="~/CMSTemplates/CorporateSiteAspx/Root.master" AutoEventWireup="true" CodeFile="temp.aspx.cs" Inherits="CMSTemplates_CorporateSiteAspx_temp" %>
<%@ Register Src="~/CMSWebParts/Viewers/Documents/cmsrepeateritem.ascx" TagName="repeater" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="plcMain" Runat="Server">
<asp:Panel ID="panel" runat="server"></asp:Panel>
</asp:Content>
Another possibility how to display number of repeater items is by changing
protected override void OnPreRender(EventArgs e) method to look like following one in code behind of cloned webpart. The other changes in this file are not needed in this case (do not modify public override void OnContentLoaded() and do not create
void repItems_DataBinding(object sender, EventArgs e) method):
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
Visible = !repItems.StopProcessing;
if (DataHelper.DataSourceIsEmpty(repItems.DataSource) && (repItems.HideControlForZeroRows))
{
Visible = false;
ltlRepeaterCount.Visible = false;
}
else
{
ltlRepeaterCount.Text = repItems.Items.Count.ToString();
}
}
This way number of repeater items will be displayed via cloned web part control.
Best regards,
Ivana Tomanickova