[转]GridView自动序号

转自:http://hi.baidu.com/yifanzhuzhu/blog/item/76492e58228ab087810a186d.html

GridView自动序号

(倒序)

<asp:TemplateField HeaderStyle-Width="30px" HeaderText="序号" ItemStyle-HorizontalAlign="center">
     <ItemTemplate>
         <asp:Label ID="Label1" runat="server" Text='<%#((Container as GridViewRow).DataItem as System.Data.DataRowView).Row.Table.Rows.Count - (Container as GridViewRow).RowIndex%>'></asp:Label>
     </ItemTemplate>
</asp:TemplateField>

(正序)

<asp:TemplateField HeaderStyle-Width="30px" HeaderText="序号" ItemStyle-HorizontalAlign="center">
     <ItemTemplate>
          <asp:Label ID="Label1" runat="server" Text='<%#(Container as GridViewRow).RowIndex + 1%>'></asp:Label>
     </ItemTemplate>
</asp:TemplateField>

posted @ 2008-11-05 11:17  xjy  阅读(500)  评论(2编辑  收藏  举报