zoukankan      html  css  js  c++  java
  • 绑定 gridview 序号

    摘过来值为方便以后的使用!

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

    页面的列为:

    <asp:BoundField  HeaderText="序号" />

    或用

    <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);
             }          
       }

    一般不考虑分页情况下大多使用

    <asp:TemplateField HeaderText="序号"> 
    <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>

       原文地址:http://blog.sina.com.cn/s/blog_677b661701011f4f.html

  • 相关阅读:
    [Java IO]04_系统标准IO
    [Java IO]03_字符流
    [Java IO]02_字节流
    [Java IO]01_File类和RandomAccessFile类
    [Java 安全]加密算法
    [Java 安全]消息摘要与数字签名
    Java正则速成秘籍(三)之见招拆招篇
    Java正则速成秘籍(一)之招式篇
    Java 枚举
    redis 系列13 集合对象
  • 原文地址:https://www.cnblogs.com/ruicky/p/2584987.html
Copyright © 2011-2022 走看看