在gridview中新增一個自動編號的欄位

最近有個需求是要在資料列表中顯示流水號,

不過資料庫中並沒有流水號的欄位,

而流水號的主要目的是要看有多少筆資料,

所以直接在gridview中顯示一個筆數編號就可以了.

而作法如下,直接在gridview中新增一個TemplateField,內容設定為<%#Container.DataItemIndex+1 %>即可.

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


posted on 2009/5/14 23:17 | 我要推薦 | 閱讀數 : 1331 | 分類[ .Net C# 技術相關 程式相關 ] 訂閱

Comments on this post

# re: 在gridview中新增一個自動編號的欄位

Left by Pete on 五月 15, 2009 3:51 下午
回覆

# re: 在gridview中新增一個自動編號的欄位

哈哈..我也用這招耶, 在datalist repeater, datareader 都適用說. ^^
Left by 非凡 on 六月 01, 2009 11:18 下午
回覆

回應:

Please add 6 and 7 and type the answer here: