欢迎来到我的地盘:今天是

若得山花插满头,莫问奴归处!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

一、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

顺序如下:
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

总结:
在GridView绑定数据开始,也就是触发DataBounding事件后,这时已经把数据从数据源取出或者说已经规定了那些数据字段将会被取出,其中 的Visible属性为false的字段的值是不会从数据源中获取的。这就是为什么当GridView使用直接在html中将Visible=false 来隐藏某一列时,会得不到该列的值。然后调用RowCreated事件把一行数据全部填充到一个gridViewRow里面,然后触发 RowDataBound事件把该行绑定到GridView的Rows中。一直到最后触发GridView的DataBound来绑定显示数据。

 

GridView的RowCreated与RowDataBound的一个区别在于RowCreated事件是这样的,不管数据是不是重新绑定到GridView,只要在GridView里新增一行记录就将引发RowCreated事件。那意味着,当发生PostBack回传事件时,哪怕数据来自视图状态,也会引发RowCreated事件。

我们使用RowCreated事件而不使用RowDataBound事件的原因在于,只有当数据明确的绑定到数据Web控件时才会引发RowDataBound事件

posted on 2008-09-18 14:53  莫问奴归处  阅读(2609)  评论(1编辑  收藏  举报
轩轩娃