欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net Gridview行绑定事件新体会

程序员文章站 2024-03-08 16:47:28
在网上搜了一下事件执行顺序,并经过测试在有分页的情况下是不正确的。事件执行顺序: 一、gridview 显示绑定的数据(默认为5行): 复制代码 代码如下: databin...
在网上搜了一下事件执行顺序,并经过测试在有分页的情况下是不正确的。
事件执行顺序:

一、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中的事件中去处理。