GridView事件執行順序@ASP.Net
一、文章1
GridView事件執行順序@ASP.Net
在一個空白頁中置入GridView和一個Button後,當使用者按下按鈕後,各事件發生的順序如下:
Page GridView Button
------------ ------------ ------------
1 Init
2 Load
3 Load
4 RowCreated
5 RowDataBound
6 DataBound
7 Click
8 PreRender
參考:http://leancoding.blogspot.tw/2008/01/gridviewaspnet.html
二、文章2:
http://www.dotblogs.com.tw/eason.yen/archive/2011/02/17/21405.aspx
[ASP.NET]關於GridView控制項常用的事件的發生順序
狀況一
直接在.aspx上拉進一個GridView控制項,
並且在Page_Load事件內去加上GridView的DataSource,
此時的事件發生順序是:
| 順序 | 事件名稱 |
| 1 | GridView1_Init |
| 2 | Page_Load |
| 3 | GridView1_DataBinding |
| 4 | GridView1_RowCreated (DataSource的資料有幾列就發生幾次) |
| 5 | GridView1_RowDataBound (DataSource的資料有幾列就發生幾次) |
| 6 | GridView1_DataBound |
| 7 | GridView1_Load |
| 8 | GridView1_PreRender |
| 9 | GridView1_Unload |
狀況二
若是在PageLoad內的DataSource繫結是寫在if(!IsPostBack)內,
此時在.aspx內加入一個Button控制項,
並且按下Button產生PostBack後,
此時事件順序是:
| 順序 | 事件名稱 |
| 1 | GridView1_Init |
| 2 | GridView1_RowCreated (DataSource的資料有幾列就發生幾次) |
| 3 | Page_Load |
| 4 | GridView1_DataBound |
| 5 | GridView1_Load |
| 6 | Button1_Click |
| 7 | GridView1_PreRender |
| 8 | GridView1_Unload |
狀況三:
相對於狀況二,
把DataSource的繫結直接寫在Page_Load內,
同樣的按下Button產生了PostBack,
綜合了狀況一和狀況二,
不難理解會出現下面的事件順序:
| 順序 | 事件名稱 |
| 1 | GridView1_Init |
| 2 | GridView1_RowCreated (DataSource的資料有幾列就發生幾次) |
| 3 | Page_Load |
| 4 | GridView1_DataBinding |
| 5 | GridView1_RowCreated (DataSource的資料有幾列就發生幾次) |
| 6 | GridView1_RowDataBound (DataSource的資料有幾列就發生幾次) |
| 7 | GridView1_DataBound |
| 8 | GridView1_Load |
| 9 | Button1_Click |
| 10 | GridView1_PreRender |
| 11 | GridView1_Unload |
三、文章3:
http://blog.kkbruce.net/2010/04/gridvieweventeventhandle.html
文章簽名檔