GridView 笔记

GridView 序号

(正序)

方法一(不带分页):

<asp:TemplateField HeaderText="序号">
        <ItemTemplate>
<%#(Container as GridViewRow).RowIndex + 1%>
       </ItemTemplate>
</asp:TemplateField>

方法二(带分页):
<asp:TemplateField HeaderText="序号">
       <ItemTemplate>
            <%# this.GridView1.PageIndex * this.GridView1.PageSize + Container.DataItemIndex + 1%>
       </ItemTemplate>
</asp:TemplateField>

(倒序)

方法一(不带分页):

<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).DataItem as System.Data.DataRowView).Row.Table.Rows.Count - (Container as GridViewRow).RowIndex - (this.gviewList.PageIndex) * this.gviewList.PageSize%>'></asp:Label>
     </ItemTemplate>
</asp:TemplateField>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/kingboy2008/archive/2010/02/26/5328935.aspx

 

 

你可能感兴趣的:(GridView)