Kobarin's Development Blog

C#やASP.NET、公開APIなどについての記録です。

ASP.NETのRepeater・DataList・GridView・FormView・DetailsViewで通し番号

GridView

<asp:GridView ID="GridView1" runat="server">
  <Columns>
    <asp:TemplateField HeaderText="Number">
      <ItemTemplate>
        <%# Container.DataItemIndex + 1  %>
      </ItemTemplate>
    </asp:TemplateField>
  </Columns>
</asp:GridView>

Repeater

<asp:Repeater ID="Repeater1" runat="server">
  <ItemTemplate>
    <asp:Label ID="lblIndex" runat="server" Text='<%# Container.ItemIndex + 1 %>' />
  </ItemTemplate>
</asp:Repeater>

DataList

<asp:DataList runat="server" ID="DataList1">
  <ItemTemplate>
    <asp:Label ID="lblIndex" runat="server" Text='<%# Container.ItemIndex + 1  %>' />
  </ItemTemplate>
</asp:DataList>

FormView

<asp:FormView ID="FormView1" runat="server">
  <ItemTemplate>
    <asp:Label ID="lblIndex" runat="server" Text='<%# Container.DataItemIndex + 1  %>' />
  </ItemTemplate>
</asp:FormView>

DetailsView

<asp:DetailsView ID="DetailsView1" runat="server">
  <Fields>
    <asp:TemplateField>
      <ItemTemplate>
        <asp:Label ID="lblIndex" runat="server" Text='<%# Container.DataItemIndex + 1  %>' />
      </ItemTemplate>
    </asp:TemplateField>
  </Fields>
</asp:DetailsView>