GridView的RowCreated与RowDataBound事件区别

在西门子面试时,项目负责人除了道试题关于RowCreated与RowDataBound事件区别,经过google一下,得出结果:

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

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

RowDataBound是数据绑定的时候才会触发,RowCreated是每次呈现的时候都要触发,RowCreated先于RowDataBound执行。

举个列,如果页面回发后发生过GridView.databind(),那么两个事件都会触发。如果没发生GridView.databind(),那么就只会触发RowCreated。

事件执行顺序:

一、GridView 显示绑定的数据顺序如下:

DataBinding ->RowCreated ->RowDataBound ->...... ->DataBound

二、GridView 点击分页按钮时的事件发生顺序:

RowCommand >PageIndexChanging >PageIndexChanged >DataBinding >RowCreated:Header>RowDataBound > RowCreated:DataRow >RowDataBound >RowCreated:Footer>RowDataBound >RowCreated:Pager >RowDataBound> 
DataBound

理解也就是在点跳页按钮的时候,只会绑定要显示的页的资料,如上,因此在RowDataBound中不会绑定所有的资料,此时去统计,只能统计出当前页的加总。

目前想来,也只有对要绑定的资料进行统计了。不能在GridView中的事件中去处理。

上一篇:201301 JAVA题目0-1级


下一篇:request 获取请求参数