Site structure
Version 7.x > Site structure > Repeater for counting results View modes: 
User avatar
Member
Member
wessel.peeters-ibl-software - 11/4/2013 4:46:33 AM
   
Repeater for counting results
Hello,

Im getting stuck with the simpel fact of displaying the count result from a Repeater with a custom Query.

This is what i was looking for:
http://devnet.kentico.com/Knowledge-Base/Web-parts-Controls/How-to-display-number-of-records-in-repeater.aspx

I made the copy from the repeater and followed the steps. Butt i keep getting the following error:
[Error loading the WebPart 'Tel_projecten' of type 'queryrepeater_1']
c:\TFS\KlantenPortaal_70\CMSWebParts\Viewers\Query\queryrepeater_2.ascx.cs(619): error CS0103: De naam ltlRepeaterCount bestaat niet in de huidige context (The name don't exist)

And i think i followed the tutorial the right way.

Please help.

User avatar
Member
Member
kentico_sandroj - 11/4/2013 4:35:47 PM
   
RE:Repeater for counting results
Hello,

I have just configured this example in my instance and it seems to work as expected, the issue is likely in the code. Based on the translation of the error, it seems that ltlRepeaterCount ID does not exist but it is referenced in the codebehind. Would it be possible to check the queryrepeater_2.ascx file and ensure that the Label ID is ltlRepeaterCount. If that seems correct, would it be possible to provide the code that you are using so that we can review it?

Please let me know if you have any questions.

Best Regards,
Sandro

User avatar
Member
Member
wessel.peeters-ibl-software - 11/5/2013 3:24:40 AM
   
RE:Repeater for counting results
Offcourse i appreciate your help.

And i gave the new repeater the ID ltlRepeaterCount

This is the code from: qeuryrepeater_2
using System;
using System.Data;
using System.Web;
using System.Web.UI;

using CMS.Controls;
using CMS.GlobalHelper;
using CMS.PortalControls;

public partial class CMSWebParts_Viewers_Query_queryrepeater_2 : CMSAbstractWebPart
{
#region "Document properties"

/// <summary>
/// Load pages individually.
/// </summary>
public bool LoadPagesIndividually
{
get
{
return ValidationHelper.GetBoolean(GetValue("LoadPagesIndividually"), false);
}
set
{
SetValue("LoadPagesIndividually", value);
}
}


/// <summary>
/// Gets or sets the cache item name.
/// </summary>
public override string CacheItemName
{
get
{
return base.CacheItemName;
}
set
{
base.CacheItemName = value;
repItems.CacheItemName = value;
}
}


/// <summary>
/// Cache dependencies, each cache dependency on a new line.
/// </summary>
public override string CacheDependencies
{
get
{
return ValidationHelper.GetString(base.CacheDependencies, repItems.CacheDependencies);
}
set
{
base.CacheDependencies = value;
repItems.CacheDependencies = value;
}
}


/// <summary>
/// Gets or sets the cache minutes.
/// </summary>
public override int CacheMinutes
{
get
{
return base.CacheMinutes;
}
set
{
base.CacheMinutes = value;
repItems.CacheMinutes = value;
}
}


/// <summary>
/// Gets or sets the order by clause.
/// </summary>
public string OrderBy
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("OrderBy"), repItems.OrderBy), repItems.OrderBy);
}
set
{
SetValue("OrderBy", value);
repItems.OrderBy = value;
}
}


/// <summary>
/// Gets or sets the where condition.
/// </summary>
public string WhereCondition
{
get
{
return DataHelper.GetNotEmpty(GetValue("WhereCondition"), repItems.WhereCondition);
}
set
{
SetValue("WhereCondition", value);
repItems.WhereCondition = value;
}
}


/// <summary>
/// Gets or sets the number which indicates how many documents should be displayed.
/// </summary>
public int SelectTopN
{
get
{
return ValidationHelper.GetInteger(GetValue("SelectTopN"), repItems.SelectTopN);
}
set
{
SetValue("SelectTopN", value);
repItems.SelectTopN = value;
}
}

#endregion


#region "Pager properties"

/// <summary>
/// Gets or sets the value that indicates whether paging is enabled.
/// </summary>
public bool EnablePaging
{
get
{
return ValidationHelper.GetBoolean(GetValue("EnablePaging"), repItems.EnablePaging);
}
set
{
SetValue("EnablePaging", value);
repItems.EnablePaging = value;
}
}


/// <summary>
/// Gets or sets the pager position.
/// </summary>
public PagingPlaceTypeEnum PagerPosition
{
get
{
return repItems.PagerControl.GetPagerPosition(DataHelper.GetNotEmpty(GetValue("PagerPosition"), repItems.PagerControl.PagerPosition.ToString()));
}
set
{
SetValue("PagerPosition", value.ToString());
repItems.PagerControl.PagerPosition = value;
}
}


/// <summary>
/// Gets or sets the number of the documents displayed on each sigle page.
/// </summary>
public int PageSize
{
get
{
return ValidationHelper.GetInteger(GetValue("PageSize"), repItems.PageSize);
}
set
{
SetValue("PageSize", value);
repItems.PageSize = value;
}
}


/// <summary>
/// Gets or sets the pager query string key.
/// </summary>
public string QueryStringKey
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("QueryStringKey"), repItems.PagerControl.QueryStringKey), repItems.PagerControl.QueryStringKey);
}
set
{
SetValue("QueryStringKey", value);
repItems.PagerControl.QueryStringKey = value;
}
}


/// <summary>
/// Gets or sets whether PostBack or QueryString should be used for the paging.
/// </summary>
public PagingModeTypeEnum PagingMode
{
get
{
return repItems.PagerControl.GetPagingMode(DataHelper.GetNotEmpty(GetValue("PagingMode"), repItems.PagerControl.PagingMode.ToString()));
}
set
{
SetValue("PagingMode", value.ToString());
repItems.PagerControl.PagingMode = value;
}
}


/// <summary>
/// Gets or sets the navigation mode.
/// </summary>
public BackNextLocationTypeEnum BackNextLocation
{
get
{
return repItems.PagerControl.GetBackNextLocation(DataHelper.GetNotEmpty(GetValue("BackNextLocation"), repItems.PagerControl.BackNextLocation.ToString()));
}
set
{
SetValue("BackNextLocation", value.ToString());
repItems.PagerControl.BackNextLocation = value;
}
}


/// <summary>
/// Gets or sets the value that indicates whether first and last page is shown if paging is allowed.
/// </summary>
public bool ShowFirstLast
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowFirstLast"), repItems.PagerControl.ShowFirstLast);
}
set
{
SetValue("ShowFirstLast", value);
repItems.PagerControl.ShowFirstLast = value;
}
}


/// <summary>
/// Gets or sets the html before pager.
/// </summary>
public string PagerHTMLBefore
{
get
{
return ValidationHelper.GetString(GetValue("PagerHTMLBefore"), repItems.PagerControl.PagerHTMLBefore);
}
set
{
SetValue("PagerHTMLBefore", value);
repItems.PagerControl.PagerHTMLBefore = value;
}
}


/// <summary>
/// Gets or sets the html after pager.
/// </summary>
public string PagerHTMLAfter
{
get
{
return ValidationHelper.GetString(GetValue("PagerHTMLAfter"), repItems.PagerControl.PagerHTMLAfter);
}
set
{
SetValue("PagerHTMLAfter", value);
repItems.PagerControl.PagerHTMLAfter = value;
}
}


/// <summary>
/// Gets or sets the results position.
/// </summary>
public ResultsLocationTypeEnum ResultsPosition
{
get
{
return repItems.PagerControl.GetResultPosition(ValidationHelper.GetString(GetValue("ResultsPosition"), ""));
}
set
{
SetValue("ResultsPosition", value);
repItems.PagerControl.ResultsLocation = value;
}
}


/// <summary>
/// Gets or sets the page numbers separator.
/// </summary>
public string PageNumbersSeparator
{
get
{
return ValidationHelper.GetString(GetValue("PageNumbersSeparator"), repItems.PagerControl.PageNumbersSeparator);
}
set
{
SetValue("PageNumbersSeparator", value);
repItems.PagerControl.PageNumbersSeparator = value;
}
}

#endregion


#region "Public properties"

/// <summary>
/// Gets or sets the value that indicates whether control should be hidden if no data found.
/// </summary>
public bool HideControlForZeroRows
{
get
{
return ValidationHelper.GetBoolean(GetValue("HideControlForZeroRows"), repItems.HideControlForZeroRows);
}
set
{
SetValue("HideControlForZeroRows", value);
repItems.HideControlForZeroRows = value;
}
}


/// <summary>
/// Gets or sets the text which is displayed for zero rows result.
/// </summary>
public string ZeroRowsText
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("ZeroRowsText"), repItems.ZeroRowsText), repItems.ZeroRowsText);
}
set
{
SetValue("ZeroRowsText", value);
repItems.ZeroRowsText = value;
}
}


/// <summary>
/// Gets or sets the separator (tetx, html code) which is displayed between displayed items.
/// </summary>
public string ItemSeparator
{
get
{
return DataHelper.GetNotEmpty(GetValue("ItemSeparator"), repItems.ItemSeparator);
}
set
{
SetValue("ItemSeparator", value);
repItems.ItemSeparator = value;
}
}


/// <summary>
/// Filter name.
/// </summary>
public string FilterName
{
get
{
return ValidationHelper.GetString(GetValue("FilterName"), repItems.FilterName);
}
set
{
SetValue("FilterName", value);
repItems.FilterName = value;
}
}


/// <summary>
/// Gets or sets query string key name. Presence of the key in query string indicates,
/// that some item should be selected. The item is determined by query string value.
/// </summary>
public string SelectedQueryStringKeyName
{
get
{
return ValidationHelper.GetString(GetValue("SelectedQueryStringKeyName"), repItems.SelectedQueryStringKeyName);
}
set
{
SetValue("SelectedQueryStringKeyName", value);
repItems.SelectedQueryStringKeyName = value;
}
}


/// <summary>
/// Gets or sets columns name by which the item is selected.
/// </summary>
public string SelectedDatabaseColumnName
{
get
{
return ValidationHelper.GetString(GetValue("SelectedDatabaseColumnName"), repItems.SelectedDatabaseColumnName);
}
set
{
SetValue("SelectedDatabaseColumnName", value);
repItems.SelectedDatabaseColumnName = value;
}
}


/// <summary>
/// Gets or sets validation type for query string value which determines selected item.
/// Options are int, guid and string.
/// </summary>
public string SelectedValidationType
{
get
{
return ValidationHelper.GetString(GetValue("SelectedValidationType"), repItems.SelectedValidationType);
}
set
{
SetValue("SelectedValidationType", value);
repItems.SelectedValidationType = value;
}
}

#endregion


#region "Data binding properties"

/// <summary>
/// Gets or sets the value that indicates whether databind will be proceeded automatically.
/// </summary>
public bool DataBindByDefault
{
get
{
return ValidationHelper.GetBoolean(GetValue("DataBindByDefault"), repItems.DataBindByDefault);
}
set
{
SetValue("DataBindByDefault", value);
repItems.DataBindByDefault = value;
}
}


/// <summary>
/// Gets or sets the query name.
/// </summary>
public string QueryName
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("QueryName"), repItems.QueryName), repItems.QueryName);
}
set
{
SetValue("QueryName", value);
repItems.QueryName = value;
}
}


/// <summary>
/// Gets or sets selected columns.
/// </summary>
public string Columns
{
get
{
return ValidationHelper.GetString(GetValue("Columns"), repItems.Columns);
}
set
{
SetValue("Columns", value);
repItems.SelectedColumns = value;
}
}

#endregion


#region "Transformation properties"

/// <summary>
/// Gets or sets the name of the transforamtion which is used for displaying the results.
/// </summary>
public string TransformationName
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("TransformationName"), repItems.TransformationName), repItems.TransformationName);
}
set
{
SetValue("TransformationName", value);
repItems.TransformationName = value;
}
}


/// <summary>
/// Gets or sets the name of the transforamtion which is used for displaying the alternate results.
/// </summary>
public string AlternatingTransformationName
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("AlternatingTransformationName"), repItems.AlternatingTransformationName), repItems.AlternatingTransformationName);
}
set
{
SetValue("AlternatingTransformationName", value);
repItems.AlternatingTransformationName = value;
}
}


/// <summary>
/// Gets or sets ItemTemplate for selected item.
/// </summary>
public string SelectedItemTransformationName
{
get
{
return ValidationHelper.GetString(GetValue("SelectedItemTransformationName"), "");
}
set
{
SetValue("SelectedItemTransformationName", value);
repItems.SelectedItemTransformationName = value;
}
}

#endregion


#region "Editing mode buttons properties"

/// <summary>
/// Gets or sets the value that indicates whether edit and delete buttons should be displayed.
/// </summary>
public bool ShowEditDeleteButtons
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowEditDeleteButtons"), repItems.ShowEditDeleteButtons);
}
set
{
SetValue("ShowEditDeleteButtons", value);
repItems.ShowEditDeleteButtons = value;
}
}

#endregion


#region "Stop processing"

/// <summary>
/// Returns true if the control processing should be stopped.
/// </summary>
public override bool StopProcessing
{
get
{
return base.StopProcessing;
}
set
{
base.StopProcessing = value;
repItems.StopProcessing = value;
}
}

#endregion


/// <summary>
/// Content loaded event handler.
/// </summary>
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
this.repItems.DataBinding += new EventHandler(repItems_DataBinding);
}

void repItems_DataBinding(object sender, EventArgs e)
{
if (!CMS.GlobalHelper.DataHelper.DataSourceIsEmpty(repItems.DataSource))
{
System.Data.DataView dv = repItems.DataSource as System.Data.DataView;
if ((dv != null) && (dv.Table != null))
{
ltlRepeaterCount.Text = dv.Table.Rows.Count.ToString();
}
}
}


/// <summary>
/// Initializes the control properties.
/// </summary>
protected void SetupControl()
{
if (StopProcessing)
{
repItems.StopProcessing = true;
}
else
{
// Add query repeater to the filter collection
CMSControlsHelper.SetFilter(ValidationHelper.GetString(GetValue("WebPartControlID"), ClientID), repItems);

// Setup the control
repItems.ControlContext = ControlContext;

// Document properties
repItems.LoadPagesIndividually = LoadPagesIndividually;
repItems.CacheItemName = CacheItemName;
repItems.CacheDependencies = CacheDependencies;
repItems.CacheMinutes = CacheMinutes;
repItems.OrderBy = OrderBy;
repItems.SelectTopN = SelectTopN;
repItems.WhereCondition = WhereCondition;
repItems.ItemSeparator = ItemSeparator;
repItems.FilterName = FilterName;
repItems.SelectedQueryStringKeyName = SelectedQueryStringKeyName;
repItems.SelectedDatabaseColumnName = SelectedDatabaseColumnName;
repItems.SelectedValidationType = SelectedValidationType;

// Pager
repItems.EnablePaging = EnablePaging;
repItems.PageSize = PageSize;
repItems.PagerControl.PagerPosition = PagerPosition;
repItems.PagerControl.QueryStringKey = QueryStringKey;
repItems.PagerControl.PagingMode = PagingMode;
repItems.PagerControl.BackNextLocation = BackNextLocation;
repItems.PagerControl.ShowFirstLast = ShowFirstLast;
repItems.PagerControl.PagerHTMLBefore = PagerHTMLBefore;
repItems.PagerControl.PagerHTMLAfter = PagerHTMLAfter;
repItems.PagerControl.ResultsLocation = ResultsPosition;
repItems.PagerControl.PageNumbersSeparator = PageNumbersSeparator;

// Public
repItems.HideControlForZeroRows = HideControlForZeroRows;
repItems.ZeroRowsText = ZeroRowsText;

// Binding
repItems.DataBindByDefault = DataBindByDefault;

// Transformations
repItems.AlternatingTransformationName = AlternatingTransformationName;
repItems.TransformationName = TransformationName;
repItems.SelectedItemTransformationName = SelectedItemTransformationName;

repItems.QueryName = QueryName;

repItems.ShowEditDeleteButtons = ShowEditDeleteButtons;
repItems.Columns = Columns;
}
}


/// <summary>
/// OnPrerender override (Set visibility).
/// </summary>
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

Visible = repItems.Visible && !StopProcessing;

if (DataHelper.DataSourceIsEmpty(repItems.DataSource) && repItems.HideControlForZeroRows)
{
Visible = false;
}
}


/// <summary>
/// Reloads the data.
/// </summary>
public override void ReloadData()
{
base.ReloadData();
SetupControl();
repItems.ReloadData(true);
}


/// <summary>
/// Clears cache.
/// </summary>
public override void ClearCache()
{
repItems.ClearCache();
}
}

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 11/5/2013 7:20:06 AM
   
RE:Repeater for counting results
In your .ascx file, make sure the two properties, CodeFile and Inherits are updated as well.

CodeFile="CMSWebParts_Views_Query_queryrepeater2.ascx.cx"
Inherits="CMSWebParts_Views_Query_queryrepeater2"

User avatar
Member
Member
wessel.peeters-ibl-software - 11/5/2013 8:23:47 AM
   
RE:Repeater for counting results
This is how my ascx file looks like:
<%@ Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_Viewers_Query_queryrepeater_2" CodeFile="~/CMSWebParts/Viewers/Query/queryrepeater_2.ascx.cs" %>

<cms:queryrepeater id="repItems" runat="server" />

I trying to copy your request butt it didn't help.
This is how i would look like with your advise:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CMSWebParts_Views_Query_queryrepeater2.ascx.cx"
Inherits="CMSWebParts_Views_Query_queryrepeater2"%>

<cms:queryrepeater id="repItems" runat="server" />

User avatar
Member
Member
kentico_sandroj - 11/5/2013 9:11:13 PM
   
RE:Repeater for counting results
Hello,

If this is the whole code for your ascx file, the issue is that you are missing the Literal or Label as specified in the documentation:
You will need to create copy of repeater web part. Into this copy please add asp:Literal control with ID="ltlRepeaterCount". Open the code-behind file of copied web part and change following lines...

Could you please confirm if that is the issue here?

Best Regards,
Sandro

User avatar
Member
Member
wessel.peeters-ibl-software - 11/6/2013 1:52:56 AM
   
RE:Repeater for counting results
<%@ Control Language="C#" ID="ltlRepeaterCount" AutoEventWireup="true" Inherits="CMSWebParts_Viewers_Query_queryrepeater_2" CodeFile="~/CMSWebParts/Viewers/Query/queryrepeater_2.ascx.cs" %>

<cms:queryrepeater id="repItems" runat="server" />

Im think you are right this is how my ascx file looks like now.
The error change now to: This ID is not supported by the instruction control.
And it don't matter what table of query i choose.

Greetings

User avatar
Member
Member
kentico_sandroj - 11/6/2013 9:28:54 PM
   
RE:Repeater for counting results
Hello,

Thank you for providing the code. Please try changing your ASCX file to the following:
<%@ Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_Viewers_Query_queryrepeater_2" CodeFile="~/CMSWebParts/Viewers/Query/queryrepeater_2.ascx.cs" %>
<asp:Label ID="ltlRepeaterCount" runat="server" Text="Label"></asp:Label>
<cms:queryrepeater id="repItems" runat="server" />

As shown in the above example, there should be a Label control on the page with the ID of ltlRepeaterCount. I have placed this control before the repeater so the number of results will show above the repeater on your site.

Please let me know if you have any questions.

Best Regards,
Sandro

User avatar
Member
Member
wessel.peeters-ibl-software - 11/7/2013 2:31:09 AM
   
RE:Repeater for counting results
Thank you for your help again.
It now shows all the results. With the total number in front of it.
Will it also by possible to publish only the total number ?

I all ready tried to change this part to visible="false" :
<cms:queryrepeater id="repItems" visible="false"  runat="server" />

But then the repeater shows nothing at all.

User avatar
Member
Member
kentico_sandroj - 11/8/2013 6:21:46 PM
   
RE:Repeater for counting results
Hello,

The easiest approach for showing only a number of items in that repeater would likely be creating an empty transformation. Adding the following value to the transformation would allow you to save but would not output anything: &#173

Would this approach work for you?

Best Regards,
Sandro

User avatar
Member
Member
wessel.peeters-ibl-software - 11/15/2013 8:14:53 AM
   
RE:Repeater for counting results
Its working now.
Thank you all very much for the help so far.

Best Regards,
Wessel