zoukankan      html  css  js  c++  java
  • GridView序号

    GridView控件中加自动序号,有多种实现方法,你只需要根据的实用要求来确定。总的来分为后台写法和前台写法,后台写法一般不考虑分页的情况下使用,原理就是在GridView 绑定数据时,在RowDataBound 事件中来处理。

    1.前台

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

    下面考虑的主要是分页情况下的,在ASP.NET中分页方法一般用GridView自带的分页工具和AspNetPager的比较多。GridView自带的分页写法:

    <asp:TemplateField HeaderText="序号"> 
    <ItemTemplate> 
    <%# this.GridView1.PageIndex  * this.GridView1.PageSize 
    
             + GridView1.Rows.Count + 1%> 
    </ItemTemplate> 
    </asp:TemplateField> 

    AspNetPager分页情况下的写法为:

    <asp:TemplateField HeaderText="序号"> 
    <ItemTemplate> 
       <%# (this.Pager1.CurrentPageIndex - 1) * this.Pager1.PageSize 
    
        + Container.DataItemIndex + 1%> 
    </ItemTemplate> 
    </asp:TemplateField>

    2.后台

    <asp:TemplateField HeaderText="序号"> 
    <ItemTemplate> 
    </ItemTemplate> 
    </asp:TemplateField> 

    cs中

    protected void GridView1_RowDataBond(object sender, GridViewRowEventArgs e)
    {
             if (e.Row.RowIndex >= 0)
             {
              e.Row.Cells[0].Text = Convert.ToString(e.Row.RowIndex + 1);
             }           
       }
  • 相关阅读:
    AtCoder Regular Contest 061
    Codeforces Round #370 (Div. 2)
    2016 ACM/ICPC Asia Regional Dalian Online
    HDU 5513 Efficient Tree
    Codeforces Round #104 (Div. 1)
    2016 Hunan Province Programming Contest
    2016 Multi-University Training Contest 7
    2016中国大学生程序设计竞赛
    聚会「AHOI 2008」
    游戏「AHOI / HNOI2018」
  • 原文地址:https://www.cnblogs.com/yzj1212/p/2586444.html
Copyright © 2011-2022 走看看