I never use AlternatingItemTemplate
. I donβt like duplicating my code in order to have a variable element, and I think that if the code is different from the fact that it cannot be classified as duplicate, then you should not use the Repeater
control in any case.
Therefore, I always use an ItemTemplate
and make the necessary changes to the ItemDataBound
event.
To determine if an element is a normal or variable element, I would do something like:
if ((e.Item.ItemIndex+1 % 2)=0){
In your case, the only difference is the change in Label
CssClass
, so I would do something like:
if ((e.Item.ItemIndex+1 % 2)=0){ Label lblComment = e.Item.FindControl("lblComment"); lblComment.CssClass = "alternatingTtemTemplate"; }
source share