Home > Blog > Computers & Internet > ASP.net2.0でGridViewに連番(通し番号)を振る方法

ASP.net2.0でGridViewに連番(通し番号)を振る方法

GridViewに行数(連番)はどうつけるのかなとしばらく探してみるといい記事がありましたのでのせます。

下記リンクのHello Another World!様からの引用です

Hello Another World!

ASP.net 2.0 で GridView に連番(通し番号)を振る方法
ASP.net 2.0 で GridView コントロールの行に連番(通し番号)を付ける方法です。

テンプレート列を利用して Container.DataItemIndex プロパティを呼び出します。
Container.DataItemIndex プロパティに入る数値は 0 から始まりますから、1 を起点にするなら +1 してください。

 <asp:GridView>
  <Columns>
   <asp:TemplateField>
    <ItemTemplate>
     <%# Container.DataItemIndex + 1 %>
    </ItemTemplate>
   </asp:TemplateField>
  </Columns>
 </asp:GridView>

結構探したけど、一瞬で終わった。ありがとうございます。

ASP .NET GridView 連番 index 行数 C#

Repeaterの場合

<%# Container.ItemIndex + 1 %>

でOKです。

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://clare-chronicle.net/2007/06/aspnet20%e3%81%a7gridview%e3%81%ab%e9%80%a3%e7%95%aa%e9%80%9a%e3%81%97%e7%95%aa%e5%8f%b7%e3%82%92%e6%8c%af%e3%82%8b%e6%96%b9%e6%b3%95/trackback/
Listed below are links to weblogs that reference
ASP.net2.0でGridViewに連番(通し番号)を振る方法 from Clare Chronicle

Home > Computers & Internet > ASP.net2.0でGridViewに連番(通し番号)を振る方法

Return to page top