10

I want an ASP:NET WebForms Repeater control to put an index next to each of its output rows automatically. How can I do that?

Example:

   Name
1  John
2  Jack
3  Joe
Marcel
  • 15,039
  • 20
  • 92
  • 150
Barış Velioğlu
  • 5,709
  • 15
  • 59
  • 105

1 Answers1

32

Try the following:

<asp:Repeater ID="myRepeater" runat="server">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td><%# Container.ItemIndex %></td>
            <!-- or maybe -->
            <td><%# Container.ItemIndex + 1 %></td>
            <td><%# DataBinder.Eval(Container, "DataItem.Name") %></td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>
Rawling
  • 49,248
  • 7
  • 89
  • 127