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來綁定顯示數據。
 
發佈了64 篇原創文章 · 獲贊 1 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章