代码改变世界

GridView的自动编号

2007-05-16 01:56  E2Home  阅读(588)  评论(0编辑  收藏  举报

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

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

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