在做项目的时候,客户经常要求加个自增长列,而不要放到数据库中.所以在GridView中,我们是这样处理的.
在GridView的第一列,添加一个模板列,代码如下:

1GridView的自动编号<asp:TemplateField HeaderText="序号" SortExpression="PublishSource">
2GridView的自动编号          <ItemStyle Width="15%" />
3GridView的自动编号          <ItemTemplate>
4GridView的自动编号                  <asp:Label ID="Label1" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
5GridView的自动编号          </ItemTemplate>
6GridView的自动编号 </asp:TemplateField>

网上有相关资料.
DataGrid自动编号之黄金版

相关文章: