GridView事件说明及执行顺序
来源:互联网 发布:windows api 怎么使用 编辑:程序博客网 时间:2024/06/15 17:53
作为c#开发人员,对于GridView应该是熟的不能再熟了,但是使用了这么就对于常用的事件和他们之间的关系还不是特别清楚,今天遇到了一个问题,跟踪之后才发现和GridView的执行顺序有很大的关系:
问题,页面有4个GridView列表gvListA、gvListB、gvListC、gcListD,执行A的翻页的时候需要先保存列表的数据。
第一种方案:在BeforePaging()中执行Save(),在PageIndexChanged()中执行BindGrid();会出现第一个列表翻页不成功,且后面三个列表没有绑定值的情况;
跟踪后发现,点击翻页后执行pageload(),页面回发,列表数据清空,-->再执行BeforePaging()中的Save()的时候,gvList的Rows的Count=0,因此没有保存上,在执行PageIndexChanged()的BindGrid(),重新绑定,所有翻页没有效果;失败
第二种方案:在OnRowCommand中执行BindGrid(),在BeforePaging()执行Save();
跟踪后发现,点击翻页执行顺序是:pageload()---OnRowCommand()--BeforePaging(),页面回发后列表情空,然后执行OnRowCommand()中的BindGrid(),绑定列表,此时因为文本框有页面回发数据不清空的属性,所以重新绑定后文本框中仍然有值,在执行BeforePaging()中的Save()保存列表信息
GridView绑定初始化的事件发生顺序
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
二、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
总结:
在GridView绑定数据开始,也就是触发DataBounding事件后,这时已经把数据从数据源取出或者说已经规定了那些数据字段将会被取出,其中 的Visible属性为false的字段的值是不会从数据源中获取的。这就是为什么当GridView使用直接在html中将Visible=false 来隐藏某一列时,会得不到该列的值。然后调用RowCreated事件把一行数据全部填充到一个gridViewRow里面,然后触发 RowDataBound事件把该行绑定到GridView的Rows中。一直到最后触发GridView的DataBound来绑定显示数据。
GridView的RowCreated与RowDataBound的一个区别在于RowCreated事件是这样的,不管数据是不是重新绑定到GridView,只要在GridView里新增一行记录就将引发RowCreated事件。那意味着,当发生PostBack回传事件时,哪怕数据来自视图状态,也会引发RowCreated事件。
- GridView事件说明及执行顺序
- GridView 删除按钮事件执行顺序
- GridView 删除事件的执行顺序
- GridView事件DataBinding,DataBound,RowCreated,RowDataBound区别及执行顺序分析
- GridView事件DataBinding,DataBound,RowCreated,RowDataBound区别及执行顺序分析(转)
- GridView事件DataBinding,DataBound,RowCreated,RowDataBound区别及执行顺序分析
- unity 事件(顺序及功能说明)
- unity 事件(顺序及功能说明)
- unity 事件(顺序及功能说明)
- BO常用事件及执行顺序
- GridView 事件顺序大全
- GridView 事件顺序大全
- GridView的事件说明
- GridView的事件说明
- asp.net页面事件执行顺序及各事件作用
- SQL执行顺序说明
- (原创)关于构造函数及参数执行顺序说明(c#)
- 关于构造函数及变量执行顺序说明
- css3中position定位详解
- cocos2d-x节点(base64.h)API
- Linux 上不可修改的文件和目录
- CF 362C 冒泡排序 交换哪两个数逆序数减少最多
- 技术团队新官上任之中层篇
- GridView事件说明及执行顺序
- 技术团队新官上任之基层篇
- cocos2d-x节点(CCIMEDispatcher.h)API
- 写给大家看的设计书 (第3版)
- ORA-27102: out of memory Linux-X86_64 Error: 28: No space left on device (Doc ID 301830.1)
- cocos2d-x节点(CCTextureAtlas.h)API
- cocos2d-x节点(CCTextureCache.h)API
- 用VirtualBox安装Mac OS X 10.7正式版
- Handler+thread 加载网络图片