Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easiest way to put an index to a repeater control in .NET?

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
like image 470
Barış Velioğlu Avatar asked Apr 04 '12 10:04

Barış Velioğlu


1 Answers

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>
like image 115
Rawling Avatar answered Oct 17 '22 07:10

Rawling