Gridview行綁定事件新體會

最近在做統計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中的事件中去處理。

 

來源:http://www.cnblogs.com/hovering/archive/2009/11/29/1613365.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章