| 事件 | 觸發時機 | 常見用途 |
|---|---|---|
PageIndexChanging | 分頁操作前 | 取消分頁、記錄目標頁索引 |
PageIndexChanged | 分頁完成後 | 重新繫結、恢復 UI 狀態 |
SelectedIndexChanging | 選取列前 | 驗證可否選取 |
SelectedIndexChanged | 選取完成後 | 顯示明細、啟用相關按鈕 |
Sorting | 排序前 | 自訂排序邏輯、取消排序 |
Sorted | 排序後 | 記錄排序狀態 |
RowEditing | 進入編輯模式前 | 載入下拉選單資料來源 |
RowCancelingEdit | 取消編輯前 | 清除暫存編輯資料 |
RowUpdating | 更新前 | 驗證輸入、修改 NewValues |
RowUpdated | 更新後 | 檢查例外、顯示成功訊息 |
RowDeleting | 刪除前 | 確認刪除、檢查關聯資料 |
RowDeleted | 刪除後 | 處理外鍵衝突例外 |
RowDataBound | 資料列繫結時 | 格式化顯示、動態隱藏欄位 |
RowCreated | 建立資料列時 | 動態加入控制項、設定屬性 |
RowCommand | 按鈕命令觸發 | 處理自訂 CommandName |
| 事件 | 階段 | 備註 |
|---|---|---|
Selecting/Selected | 查詢前/後 | 修改 SelectCommand、快取結果 |
Updating/Updated | 更新前/後 | 驗證參數、記錄異動日誌 |
Deleting/Deleted | 刪除前/後 | 軟刪除標記、級聯刪除 |
Inserting/Inserted | 插入前/後 | 產生流水號、發送通知 |
Filtering | 篩選前 | 必須驗證防注入 |
ObjectCreating/ObjectCreated:可在 ObjectCreating 設定 e.ObjectInstance 注入自訂實例 (如從 IoC 容器解析)。ObjectDisposing:釋放非受控資源。