第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了.

<asp:TemplateField HeaderText="序号" InsertVisible="False">
              <ItemStyle HorizontalAlign="Center" />
              <HeaderStyle HorizontalAlign="Center" Width="5%" />
             <ItemTemplate>
              <%#Container.DataItemIndex+1%>
            </ItemTemplate>
            </asp:TemplateField>

第二种方式分页时进行了计算,这样会累计向下加.

<asp:TemplateField HeaderText="序号" InsertVisible="False">
              <ItemStyle HorizontalAlign="Center" />
              <HeaderStyle HorizontalAlign="Center" Width="5%" />
             <ItemTemplate>
                 <asp:Label ID="Label2" runat="server" Text='<%# this.MyListGridView.PageIndex * this.MyListGridView.PageSize + this.MyListGridView.Rows.Count + 1%>'/>
            </ItemTemplate>
            </asp:TemplateField>

还有一种方式放在cs代码中,和第二种相似.

<asp:BoundField HeaderText="序号" >
              <ItemStyle HorizontalAlign="Center" />
              <HeaderStyle HorizontalAlign="Center" Width="5%" />
          </asp:BoundField>

protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex != -1)
            {
                int indexID = this.myGridView.PageIndex * this.myGridView.PageSize + e.Row.RowIndex + 1;
                 e.Row.Cells[0].Text = indexID.ToString();
             }
         }

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{
int indexID = this.GridView1.PageIndex * this.GridView1.PageSize + e.Row.RowIndex + 1;
e.Row.Cells[4].Text = indexID.ToString();
}
if (e.Row.RowType == DataControlRowType.DataRow ||

e.Row.RowType == DataControlRowType.EmptyDataRow)
{

var daat = e.Row.DataItem as usermodel;
iNumber = Convert.ToInt32(daat.age);
//生成总计
totalNumber += iNumber;

}

if (e.Row.RowType == DataControlRowType.Footer) //页脚
{
Label la=(Label) e.Row.FindControl("Label4");
la.Text = string.Format("年龄:{0}", totalNumber);
}
}

gridview 自动序号 合计的更多相关文章

  1. ASP.NET 为GridView添加序号列,且支持分页连续累计显示

    为GridView添加序号列,且支持分页连续累计显示,废话不多说,直接上代码: <%@ Page Language="C#" AutoEventWireup="tr ...

  2. DevExpress GridView自动滚动

    引言 最新有一个winform项目使用的是DevExpress的控件,所以最近都在摸索使用这套控件,实在是佩服整套控件的强大,同时代码写起来也简洁.客户有一个需求,希望报表结果能在外接的大屏幕上定时滚 ...

  3. GridView,Repeater增加自动序号列

    有三种实现的方式, 第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. <Columns> <asp:TemplateField Hea ...

  4. asp.net 中给gridview添加自动序号

    第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. 代码如下: <asp:TemplateField HeaderText="序号&quo ...

  5. 使用模板技术处理ASP.NET中GridView额外序号列的问题

    问题描述: 现在要在一张GridView表中添加一列来显示行号,要求是显示下一页的时候能够递增而不是从新编号.数据库中的没有相关序号列 如何在软件端实现呢? 通过测试,添加以下代码即可解决需求. &l ...

  6. aspxgridView,Repeater增加自动序号列

    第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. <asp:TemplateField HeaderText="序号" Ins ...

  7. Gridview里添加合计行

    ShowFooter="true" ; ; ; protected void gvIncomeYG_RowDataBound(object sender, GridViewRowE ...

  8. [转]DevExpress.XtraGrid.GridControl gridView自动列宽代码

    gridView1.OptionsView.ColumnAutoWidth = false;   for (int I = 0; I < gridView1.Columns.Count; I++ ...

  9. gridView自动列宽代码

    gridView1.OptionsView.ColumnAutoWidth = false; for (int I = 0; I < gridView1.Columns.Count; I++) ...

随机推荐

  1. Shell脚本中点号+文件名的作用

    熟悉linux是程序员必须具备的技能,水滴石穿,一点点学习吧. linux中一个文件是根据其是否具有执行属性来判断他是否可以直接运行的.就像windows下的exe一样. 如果我们要执行某一个文件,可 ...

  2. jenkins+python+kubectl实现批量更新k8s镜像

    一.jenkins使用官方镜像(官方镜像默认是jenkins用户,权限太低) 因此通过dockerfile重新改为root启动 FROM jenkins/jenkins:lts MAINTAINER ...

  3. java容器——Collection接口

    Collection是Set,List接口的父类接口,用于存储集合类型的数据. 2.方法 int size():返回集合的长度 void clear():清除集合里的所有元素,将集合长度变为0 Ite ...

  4. OC 归档和解档

    #import <Foundation/Foundation.h> #define PATH @"/Users/mac/Desktop/file.txt" int ma ...

  5. 等待进程结束wait,waitpid

    当子进程先于父进程退出时,如果父进程没有调用wait和waitpid函数,子进程就会进入僵死状态. pid_t wait(int *status); pid_t waitpid(pid_t pid, ...

  6. hibernate--一级和二级缓存(使用Ehcache)以及查询缓存

    https://blog.csdn.net/u012411414/article/details/50483185 有一下几点需要理清才行: 一级缓存是session缓存 session关闭就小时 二 ...

  7. json添加数据

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. (zz)设置单元格的宽度和高度

    (zz)设置单元格的宽度和高度 博客分类: POI生成Excel   在Excel中,单元格的宽度其实就是列的宽度,因为Excel假设这一列的单元格的宽度肯定一致.所以要设置单元格的宽度,我们就得从列 ...

  9. [转载]彻底卸载oracleXE数据库服务器

    URL:http://www.2cto.com/database/201306/216182.html

  10. 抓取错误之onerror

    一处定义,可以抓取全局的错误,相当于一个全局的try catch呀. <html> <head> <script type="text/javascript&q ...