Search code examples
c#htmlasp.netrepeater

Repeater div id changing inside repeater


I am trying to change the id of certain div/divs inside of repeater is there any psefic way to do it and can you be please explain basicaly.

<ItemTemplate>
    <li id="11">
        <img src="../<%#Eval("MediumPath")%>"class="items"alt='<%#Eval("Alt") %>'>
        <br clear="all" />
        <div><%# Eval("ProductName")%></div>
     </li>
 </ItemTemplate>


Solution

  • You can use container.ItemIndex, which gets the item index from the repeater. Just a note that it's 0 indexed so the actual code will be:

    <li id="<%# Container.ItemIndex + 1 %>">