Numbered Menu Repeater - starting at 2, instead of 1

L Younkins asked on March 1, 2022 19:34

I have a menu repeater that has a number next to each menu item. After adding 3 new menu items, it now is starting the numbering at 2, instead of 1, as it did before I added the 3 new items. You an see the page here - click on menu to see what I mean. www.macem.org

Recent Answers


Eugene Paden answered on March 1, 2022 20:23

what's your data source for the numbering?

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 1, 2022 20:33 (last edited on March 1, 2022 20:34)

Pages that are under the datalist group.

Here is the transformation Code <%# IsCurrentDocument() ? "<div class=\"IndexCircle\"><div class=\"Num\">" + (DisplayIndex + 1) + "</div></div>" : "" %> Here is the script:

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 1, 2022 20:34

<script runat=server>
protected string OutputMenuItemLI(object DataItem)
{
  bool isTrainingOption = (string)DataBinder.Eval(DataItem, "ClassDisplayName") != "Page (menu item)";
  string DocumentName = HTMLEncode(DataBinder.Eval(DataItem, "DocumentName") as string);
  string DocumentMenuCaption = DataBinder.Eval(DataItem, "DocumentMenuCaption") as string;

  string liHTML = "<li class=\"" + (IsCurrentDocument() ? "CMSListMenuHighlightedLI" : "CMSListMenuLI");  
  if (isTrainingOption)
    liHTML += " Circle";
  liHTML += "\">";

  liHTML +="<a href=\"" + GetDocumentUrl() + "\"";
  liHTML += " class=\"" + (IsCurrentDocument() ? "CMSListMenuLinkHighlighted" : "CMSListMenuLink") + "\""; 
  liHTML += " title=\"" + DocumentName + "\">";

  if (isTrainingOption)
    liHTML += "<div class=\"IndexCircle\">" + DisplayIndex + "</div>";

  liHTML += "<span class=\"linkText\">";
  liHTML += String.IsNullOrEmpty(DocumentMenuCaption) ? DocumentName : DocumentMenuCaption;
  liHTML += "</span></a>";
  liHTML += "</li>";

  return liHTML;

}
</script>
<%# Eval<bool>("DocumentMenuItemHideInNavigation") ? "" : OutputMenuItemLI(DataItem) %>
1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 1, 2022 20:36

Here is transformation.

Here is transformation: <%# IsCurrentDocument() ? "<div class=\"IndexCircle\"><div class=\"Num\">" + (DisplayIndex + 1) + "</div></div>" : "" %>

1 votesVote for this answer Mark as a Correct answer

Eugene Paden answered on March 1, 2022 20:39 (last edited on March 1, 2022 20:51)

Looks like DisplayIndex now starts at 1 instead of 0, you can do a quickfix on the transformation: (DisplayIndex + 1) to just (DisplayIndex)

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 1, 2022 21:03

It is DisplayIndex +1. Here is my transformation. Oddly, it shows the numbers correctly in the CMS. Just not on the web. <%# IsCurrentDocument() ? "<div class=\"IndexCircle\"><div class=\"Num\">" + (DisplayIndex + 1) + "</div></div>" : "" %>

1 votesVote for this answer Mark as a Correct answer

Eugene Paden answered on March 1, 2022 21:28

looking at your code, in the server side script you are just using DisplayIndex not DisplayIndex + 1.

 liHTML += "<div class=\"IndexCircle\">" + DisplayIndex + "</div>";

but in your transformation,

"<div class=\"IndexCircle\"><div class=\"Num\">" + (DisplayIndex + 1) + "</div></div>" 
1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 1, 2022 21:35 (last edited on March 1, 2022 21:36)

I see now. It is in the script itself. Do I just change the DisplayIndex to (DisplayIndex + 1)in the script?

<script runat=server>
protected string OutputMenuItemLI(object DataItem)
{
  bool isTrainingOption = (string)DataBinder.Eval(DataItem, "ClassDisplayName") != "Page (menu item)";
  string DocumentName = HTMLEncode(DataBinder.Eval(DataItem, "DocumentName") as string);
  string DocumentMenuCaption = DataBinder.Eval(DataItem, "DocumentMenuCaption") as string;

  string liHTML = "<li class=\"" + (IsCurrentDocument() ? "CMSListMenuHighlightedLI" : "CMSListMenuLI");  
  if (isTrainingOption)
    liHTML += " Circle";
  liHTML += "\">";

  liHTML +="<a href=\"" + GetDocumentUrl() + "\"";
  liHTML += " class=\"" + (IsCurrentDocument() ? "CMSListMenuLinkHighlighted" : "CMSListMenuLink") + "\""; 
  liHTML += " title=\"" + DocumentName + "\">";

  if (isTrainingOption)
    liHTML += "<div class=\"IndexCircle\">" + DisplayIndex "</div>";

  liHTML += "<span class=\"linkText\">";
  liHTML += String.IsNullOrEmpty(DocumentMenuCaption) ? DocumentName : DocumentMenuCaption;
  liHTML += "</span></a>";
  liHTML += "</li>";

  return liHTML;

}
</script>
<%# Eval<bool>("DocumentMenuItemHideInNavigation") ? "" : OutputMenuItemLI(DataItem) %>
1 votesVote for this answer Mark as a Correct answer

Eugene Paden answered on March 1, 2022 22:03

Change in the code that shows DisplayIndex in the site menu, not sure if it's the transformation or server side code, better test it first :)

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 1, 2022 22:31 (last edited on March 1, 2022 22:33)

I tried adding it in in the script, and it breaks the menu part of the page. Weird thing is, it shows the correct numbers IN the cms, just not on the published page.

1 votesVote for this answer Mark as a Correct answer

Eugene Paden answered on March 1, 2022 22:36

How is the menu broken? Inspect the html code generated also share the revised code

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 2, 2022 15:13

If I add a 1 to the script - when you click the dropdown menu, you see: [TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expected[TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=be410550-d7c6-4089-a3b8-eb29e79c16c4/CMS.MenuItem/MACEM_Menu_ASCX.ascx(19): error CS1002: ; expectedtext

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 2, 2022 15:51

When I look at the page source, it shows the first menu item (Independent Study Conversion) as 1, as it should be, but on the page itself, it is showing as 2.

1 votesVote for this answer Mark as a Correct answer

Eugene Paden answered on March 2, 2022 17:21

can you show your code changes?

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 2, 2022 19:23

There do not appear to be any changes in the source code.

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 2, 2022 19:27

Here is the menu. As you can see, Independent Study is 2. It should be 1. Image Text

Here is the page itself, within the CMS. Image Text

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 2, 2022 19:29

The PageNumRepeater feeds the menu.

1 votesVote for this answer Mark as a Correct answer

Eugene Paden answered on March 2, 2022 20:10

sorry can't see the images, what code changes did you make?

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 2, 2022 20:46

http://www.macem.org/MACEM/media/MACEM_Images/MenuDropDown.JPG

http://www.macem.org/MACEM/media/MACEM_Images/IndependentStudy.JPG

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 2, 2022 21:21

It looks like you're using version 10 portal engine. I'd highly recommend using a universal/hierarchial viewer. In those transformations at given levels, you can take advantage of the NodeLevel value to determine your numbering schema.

Another option if you plan to use that number in different areas of the site is to add a field with a dropdown selector to the page type. This may be a better solution so you don't have to worry about trying to dynamically get/generate everything (which may be overcomplicating something very simple).

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 2, 2022 21:28 (last edited on March 2, 2022 21:28)

Can you clarify what you mean by universal/hierarchical viewer? Our college upgraded the main cms to version 12, but this site, is for a sub-group within the college called MACEM (Mid-Atlantic Center for Emergency Management), and it uses a stand alone free version.

If I want to do the second option you mentioned, would I just add the field to the transformation?

Here is the transformation code: <%# IsCurrentDocument() ? "<div class=\"IndexCircle\"><div class=\"Num\">" + (DisplayIndex + 1) + "</div></div>" : "" %>

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 2, 2022 21:31

The field would need to be added to the page type being used. Once it's added to the page type, you need to populate the field with data from the Pages application for each page. After you populate that data then you need to update your transformation to get that data from the page.

It sounds like you're either very new to Kentico or don't know the backend configuration/development abilities within Kentico, so this may be a bit more of a task than you're able to take on.

1 votesVote for this answer Mark as a Correct answer

Eugene Paden answered on March 2, 2022 21:37

what's the effect if you changed:

<%# IsCurrentDocument() ? "<div class=\"IndexCircle\"><div class=\"Num\">" + (DisplayIndex + 1) + "</div></div>" : "" %>

to just

<%# IsCurrentDocument() ? "<div class=\"IndexCircle\"><div class=\"Num\">" + DisplayIndex + "</div></div>" : "" %>

I checked the generated page code and the menu starts with 2 while another section starts with 1.

Image Text

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 2, 2022 21:55

I have created new page types and transformations, but don't know much about the back end. I will add a new field to the page type and adjust the transformation.

The menu on this page used to work, so I am not sure why it starting using 2 as the starting number.

1 votesVote for this answer Mark as a Correct answer

vasu yerramsetti answered on March 3, 2022 05:48 (last edited on March 3, 2022 05:49)

L Younkins - I replicated this requirement in my local(Corporate website) as per your requirement using DataList web part.

  1. DataList webs part settings
  • Path:/Products/%
  • Maximum nesting level:1
  • ORDER BY expression:NodeOrder
  • WHERE condition:DocumentMenuItemHideInNavigation=0
  • Transformation:[transforation name]

2.Transformation (ASCX)

<li>
 <a href="<%#GetDocumentUrl()%>"> <%# Eval("ClassName").ToString().Contains("CMS.MenuItem") ? DisplayIndex + 1 + "." : ""%>
 <%# Eval("DocumentName")%> [<%# Eval("ClassName")%>]
   </a>
</li>

3.Refer attached screenshot for Content tree structure and result on page

Content Tree Structure:

Image Text

Result on Web page:

Image Text

Hope it helps you!!

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 3, 2022 15:08

The transformation for the menu uses a script. It worked properly last week. I created a new page this week, but it was in the wrong place, so I deleted it. This is when the numbering issue started. The issue is only on the dropdown menu. The page numbers are correct on the pages themselves. Here is the script it is using.

    <script runat=server>
protected string OutputMenuItemLI(object DataItem)
{
  bool isTrainingOption = (string)DataBinder.Eval(DataItem, "ClassDisplayName") != "Page (menu item)";
  string DocumentName = HTMLEncode(DataBinder.Eval(DataItem, "DocumentName") as string);
  string DocumentMenuCaption = DataBinder.Eval(DataItem, "DocumentMenuCaption") as string;

  string liHTML = "<li class=\"" + (IsCurrentDocument() ? "CMSListMenuHighlightedLI" : "CMSListMenuLI");  
  if (isTrainingOption)
    liHTML += " Circle";
  liHTML += "\">";

  liHTML +="<a href=\"" + GetDocumentUrl() + "\"";
  liHTML += " class=\"" + (IsCurrentDocument() ? "CMSListMenuLinkHighlighted" : "CMSListMenuLink") + "\""; 
  liHTML += " title=\"" + DocumentName + "\">";

  if (isTrainingOption)
    liHTML += "<div class=\"IndexCircle\">" + DisplayIndex +  "</div>";

  liHTML += "<span class=\"linkText\">";
  liHTML += String.IsNullOrEmpty(DocumentMenuCaption) ? DocumentName : DocumentMenuCaption;
  liHTML += "</span></a>";
  liHTML += "</li>";

  return liHTML;

}
</script>
<%# Eval<bool>("DocumentMenuItemHideInNavigation") ? "" : OutputMenuItemLI(DataItem) %>
1 votesVote for this answer Mark as a Correct answer

vasu yerramsetti answered on March 3, 2022 15:35

I did not understand why you mentioned two times the following condition in your script -

if (isTrainingOption)

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 3, 2022 15:43

I didnt write the script. It has been in place and working, for 5 years. It is also using the following transformation:

<%# IsCurrentDocument() ? "<div class=\"IndexCircle\"><div class=\"Num\">" + (DisplayIndex + 1) + "</div></div>" : "" %>
1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 3, 2022 15:44

TrainingOption is the page type.

1 votesVote for this answer Mark as a Correct answer

vasu yerramsetti answered on March 3, 2022 16:06

Is it developed on Portal Engine Or ASPX model? Please share here how they declared datalist web part on Master page.

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 3, 2022 20:09

Developed in Portal version 10.

1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 3, 2022 20:21

This is the script that I think powers the drop down menu at the top: <script runat=server>
    protected string OutputMenuItemLI(object DataItem)
    {
      bool isTrainingOption = (string)DataBinder.Eval(DataItem, "ClassDisplayName") != "Page (menu item)";
      string DocumentName = HTMLEncode(DataBinder.Eval(DataItem, "DocumentName") as string);
      string DocumentMenuCaption = DataBinder.Eval(DataItem, "DocumentMenuCaption") as string;

      string liHTML = "<li class=\"" + (IsCurrentDocument() ? "CMSListMenuHighlightedLI" : "CMSListMenuLI");  
      if (isTrainingOption)
        liHTML += " Circle";
      liHTML += "\">";

      liHTML +="<a href=\"" + GetDocumentUrl() + "\"";
      liHTML += " class=\"" + (IsCurrentDocument() ? "CMSListMenuLinkHighlighted" : "CMSListMenuLink") + "\""; 
      liHTML += " title=\"" + DocumentName + "\">";

      if (isTrainingOption)
        liHTML += "<div class=\"IndexCircle\">" + DisplayIndex +  "</div>";

      liHTML += "<span class=\"linkText\">";
      liHTML += String.IsNullOrEmpty(DocumentMenuCaption) ? DocumentName : DocumentMenuCaption;
      liHTML += "</span></a>";
      liHTML += "</li>";

      return liHTML;

    }
    </script>
    <%# Eval<bool>("DocumentMenuItemHideInNavigation") ? "" : OutputMenuItemLI(DataItem) %>
1 votesVote for this answer Mark as a Correct answer

Eugene Paden answered on March 4, 2022 16:42

try to do a minor non-visible change on that code and see if it is reflected on the page and confirm that this code fragment is driving the menu. it looks like it is based on the generated page but better to confirm.

your generated code starts with:

<ul id="RepeaterMenu" class="CMSListMenuUL">
  ....menu items here
</ul>
1 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 4, 2022 21:04

The menu itself, is a repeater on the master page. I tried adding a period within the

    (in the html envelope) and it showed up in the menu. I have since removed it.

    Here are what the menu repeater properties look like: http://www.macem.org/MACEM/media/MACEM_Images/MenuRepeater.JPG http://www.macem.org/MACEM/media/MACEM_Images/MenuRepeaterProperties.JPG

    Here is the transformation code for the repeater:

        <script runat=server>
    protected string OutputMenuItemLI(object DataItem)
    {
      bool isTrainingOption = (string)DataBinder.Eval(DataItem, "ClassDisplayName") != "Page (menu item)";
      string DocumentName = HTMLEncode(DataBinder.Eval(DataItem, "DocumentName") as string);
      string DocumentMenuCaption = DataBinder.Eval(DataItem, "DocumentMenuCaption") as string;
    
      string liHTML = "<li class=\"" + (IsCurrentDocument() ? "CMSListMenuHighlightedLI" : "CMSListMenuLI");  
      if (isTrainingOption)
        liHTML += " Circle";
      liHTML += "\">";
    
      liHTML +="<a href=\"" + GetDocumentUrl() + "\"";
      liHTML += " class=\"" + (IsCurrentDocument() ? "CMSListMenuLinkHighlighted" : "CMSListMenuLink") + "\""; 
      liHTML += " title=\"" + DocumentName + "\">";
    
      if (isTrainingOption)
        liHTML += "<div class=\"IndexCircle\">" + DisplayIndex +  "</div>";
    
      liHTML += "<span class=\"linkText\">";
      liHTML += String.IsNullOrEmpty(DocumentMenuCaption) ? DocumentName : DocumentMenuCaption;
      liHTML += "</span></a>";
      liHTML += "</li>";
    
      return liHTML;
    
    }
    </script>
    <%# Eval<bool>("DocumentMenuItemHideInNavigation") ? "" : OutputMenuItemLI(DataItem) %>
    
1 votesVote for this answer Mark as a Correct answer

vasu yerramsetti answered on March 5, 2022 06:37 (last edited on March 5, 2022 06:43)

I have replicated same on my local (Kentico 10) and it is working fine as expected with the following change - liHTML += "<div class=\"IndexCircle\">" + (DisplayIndex + 1) + "</div>"; for number start with 1.

Refer the attached screenshots for out put -

Image Text

Your logic is not reflecting on Website and I am assuming problem is master page because as per your screenshot for Content tree, master page redirects to another page (right Arrow icon means URL redirection) and You can find the URL redirection settings from Properties --> navigation, menu actions and share your settings and also share Settings--> Content-> Web site content section details, refer below screenshot.

Image Text

2 votesVote for this answer Mark as a Correct answer

vasu yerramsetti answered on March 5, 2022 07:12 (last edited on March 5, 2022 07:16)

Additionally try the following options -

  1. Clear cache from System--> Clear Cache and check website on Guest Browser
  2. If still persisting the same issue then go with the work around fix liHTML += "<div class=\"IndexCircle\">" + (DisplayIndex - 1) + "</div>";

for number start with 1

2 votesVote for this answer Mark as a Correct answer

L Younkins answered on March 7, 2022 16:02

That worked.

1 votesVote for this answer Mark as a Correct answer

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