当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net Gridview行绑定事件新体会

ASP.NET
Eric的无限级Tree演示
C#中操作Excel的方法(一)
Data Access Application Block V2 类库中文文档(转贴 )
大文件上传浅谈,以及遇到的问题
做软件的困难:非技术困惑
走进C# (我的C#学习之旅)之二
Northwind中一个特别之处
.net中取当前系统的想关信息的类
写组件时需要的注释与属性书写方法
XPath序列之五
使用CommandBuilder为DataAdaper生成的Command更新数据源时的注意事项!
如何列举出网络上所有的SQL Server服务器
XPath序列之一
如何在C#里面象js一样可以直接计算字符串的值
XPath序列之三
电子秤和PC之间的数据通讯(应答)
从SQL Server中读写大数据列。
通过CDO组件对NNTP服务器发送消息
Singleton深入浅出
悲观观定SQL Server和Oracle

ASP.NET 中的 asp.net Gridview行绑定事件新体会


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 94 ::
收藏到网摘: n/a

最近在做统计GridView中某一列的加总值,之前有在RowDataBound事件中中逐笔加总,经过测试才知道,这是不正确的,并不能得到所有资料的加总值。 在网上搜了一下事件执行顺序,并经过测试在有分页的情况下是不正确的。
事件执行顺序:
一、GridView 显示绑定的数据(默认为5行):
复制代码 代码如下:

DataBinding
RowCreated:Header[0]
RowDataBound
RowCreated:DataRow[1]
RowDataBound
RowCreated:DataRow[2]
RowDataBound
RowCreated:DataRow[3]
RowDataBound
RowCreated:DataRow[4]
RowDataBound
RowCreated:DataRow[5]
RowDataBound
RowCreated:Footer[6] //不管有没有页角行,该事件都会发生
RowDataBound
RowCreated:Pager[7]
RowDataBound
DataBound

顺序如下:
DataBinding
RowCreated
RowDataBound
......
DataBound
二、GridView 点击分页按钮时的事件发生顺序:
复制代码 代码如下:

RowCommand
PageIndexChanging
PageIndexChanged
DataBinding
RowCreated:Header[8]
RowDataBound
RowCreated:DataRow[9]
RowDataBound
RowCreated:DataRow[10]
RowDataBound
RowCreated:DataRow[11]
RowDataBound
RowCreated:DataRow[12]
RowDataBound
RowCreated:DataRow[13]
RowDataBound
RowCreated:Footer[14]
RowDataBound
RowCreated:Pager[15]
RowDataBound
DataBound

理解也就是在点跳页按钮的时候,只会绑定要显示的页的资料,如上,因此在RowDataBound中不会绑定所有的资料,此时去统计,只能统计出当前页的加总(如上9-13笔的资料)
目前想来,也只有对要绑定的资料进行统计了。不能在GridView中的事件中去处理。