gridview 自动序号 合计
第一种方式,直接在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 自动序号 合计的更多相关文章
- ASP.NET 为GridView添加序号列,且支持分页连续累计显示
为GridView添加序号列,且支持分页连续累计显示,废话不多说,直接上代码: <%@ Page Language="C#" AutoEventWireup="tr ...
- DevExpress GridView自动滚动
引言 最新有一个winform项目使用的是DevExpress的控件,所以最近都在摸索使用这套控件,实在是佩服整套控件的强大,同时代码写起来也简洁.客户有一个需求,希望报表结果能在外接的大屏幕上定时滚 ...
- GridView,Repeater增加自动序号列
有三种实现的方式, 第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. <Columns> <asp:TemplateField Hea ...
- asp.net 中给gridview添加自动序号
第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. 代码如下: <asp:TemplateField HeaderText="序号&quo ...
- 使用模板技术处理ASP.NET中GridView额外序号列的问题
问题描述: 现在要在一张GridView表中添加一列来显示行号,要求是显示下一页的时候能够递增而不是从新编号.数据库中的没有相关序号列 如何在软件端实现呢? 通过测试,添加以下代码即可解决需求. &l ...
- aspxgridView,Repeater增加自动序号列
第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. <asp:TemplateField HeaderText="序号" Ins ...
- Gridview里添加合计行
ShowFooter="true" ; ; ; protected void gvIncomeYG_RowDataBound(object sender, GridViewRowE ...
- [转]DevExpress.XtraGrid.GridControl gridView自动列宽代码
gridView1.OptionsView.ColumnAutoWidth = false; for (int I = 0; I < gridView1.Columns.Count; I++ ...
- gridView自动列宽代码
gridView1.OptionsView.ColumnAutoWidth = false; for (int I = 0; I < gridView1.Columns.Count; I++) ...
随机推荐
- Leetcode 113
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- CentOS7系统更换YUM Repo源
CentOS7系统更换YUM Repo源 备份原镜像 sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.re ...
- Oracle12c新特性之基本操作
1. 服务器端连接并启动数据库: sqlplus / as sysdba startup; 2. 服务器端连接并关闭数据库: sqlplus / as sysdba shutdown immedi ...
- Vue--Vue.nextTick()的使用
Vue.nextTick()是比较常用到的API Vue官网对它的解释是:在下次 DOM 更新循环结束之后执行延迟回调.在修改数据之后立即使用这个方法,获取更新后的 DOM. 首先要明白Vue的响应式 ...
- CCF 2015-03-4 网络延时
题目:http://115.28.138.223/view.page?gpid=T24 题意就是让求树上的任意两个节点间的距离的最大值.就是树的直径. 首先树的直径模板转载自http://www.07 ...
- ajax 函数的相关介绍
函数serialize serialize() 是jquery对象的一个方法,其作用是将对象的包含的值序列化为一个字符串,常用在get请求中. exp: $('#formname').serializ ...
- systemctl centos fedora 用法
LinuxSystemctl是一个系统管理守护进程.工具和库的集合,用于取代System V.service和chkconfig命令,初始进程主要负责控制systemd系统和服务管理器.通过Syste ...
- Hibernate检索学习
Hibernate的检索策略:类级别的检索策略:1对多,多对多的检索策略:多对一,一对一的检索策略 1.类级别的检索策略,可以通过class元素的lazy属性来设置,该设置只对load方法有效果 2. ...
- 软工作业No.1。Java实现WC.exe
网址:https://github.com/a249970271/WC WC 项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写一个命令行程序,模仿已有w ...
- eclipse中使用Maven新建Servlet2.5的Web项目
前言 我们用Eclipse创建Maven结构的web项目的时候选择了Artifact Id为maven-artchetype-webapp,由于这个catalog比较老,用的servlet还是2.3的 ...