How can I apply alternating styles to items in a repeater?

HelenaG Grulichova asked on August 7, 2012 05:13

How can I apply alternating styles to items in a repeater?

Correct Answer

HelenaG Grulichova answered on August 7, 2012 05:13

You can do this by making use of the DataItemIndex property.
 
The following example will create an opening div tag that uses a different class for odd and even items:
 

<%-- Add one to zero-indexed DataItemIndex --%>
<%# ((1+DataItemIndex)%2)==0?"<div class='even'>":"<div class='odd'" %>


 
See the following Knowledgebase article for more details on special properties available in transformations:
Using special item data in transformation
 

-ag-

 

0 votesVote for this answer Unmark Correct answer

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