I'm using EPiServer for this website. Unlike asp:DataList
, EPiServer:PAgeList does not have AlternatingItemTemplate
.
So I need to create a counter and increase this counter in my <ItemTemplate>
, and then use modulus to return whuch css style to append to article / page.
Modulus "code" - fromcode behind:
return index % 2 == 0 ? "styleA" : "styleB";
But I'm not abler to ad an counter and increase this in the <ItemTemplate>
.
Any suggestions much appreciated!
UPDATE
Here is my EPiServer Page List controller:
<EPiServer:PageList runat="server" id="pageList" SortDirection="Ascending" Count="4" OnDataBinding="pageList_OnDataBinding">
<HeaderTemplate>
<ul id="articleList1">
</HeaderTemplate>
<ItemTemplate>
<li>
<h2><a href="<%# Eval("LinkURL") %>" title="<%# Eval("PageName") %>"><EPiServer:Property id="Property1" PropertyName="PageName" runat="server" /></a></h2>
<div class="articleImage">
<%# ArticleImage(Container.CurrentPage)%>
</div>
<div class="introText">
<%# IntroText(Container.CurrentPage)%>
</div>
<div class="readMore floatRight"><a href="<%# Eval("LinkURL") %>" title="<%# Eval("PageName") %>">Les mer</a></div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</EPiServer:PageList>
ANSWER
I decided that using jQuery was a LOT simpler than hacking around with .NET.
It's not my preferred solution, but it works. The code I use is this:
if (jQuery("#articleList1").length > 0) {
jQuery('li:odd').addClass("odd");
}