当点击GridView中的行触发RowCommand事件时。在上面的三个事件中,首先触发的是Page_Load事件。然后执行RowCommand事件处理函数。最后执行Page_PreRender事件。
因此,如果想在事件处理函数执行完后再对页面,服务器控件做一些判断、修改等。则可以在Page_PreRender函数中处理。相反则可以在Page_Load函数中处理。
如下面的代码:
实现在gvSelTchOrderTest_RowCommand事件处理函数完成后,在Page_PreRender事件中重新处理GridView控件中包含的ImageButton控件。将特定的ImageButton控件的ImageUrl属性修改并且禁用它。
像这样的处理在Page_Load中实现将不能达到预期的效果。因为Page_Load事件在RowCommand事件之前处理,在Page_Load中作的修改有可能在RowCommand事件中被再次修改。
protected void Page_Load(object sender, EventArgs e) { //…代码 }
| ||
protected void Page_PreRender() { //--------------按钮灰色显示------------------ DataSet dsTmp = (DataSet)Session["dsSelTchOrder"]; int count = dsTmp.Tables["SelTchOrder"].Rows.Count; if (count > 0) { ImageButton imgBtn = (ImageButton)gvSelTchOrderTest.Rows[0].FindControl("ibtnUp");//.FindControl("ibtnDown"); ImageButton imgBtn2 = (ImageButton)gvSelTchOrderTest.Rows[count - 1].FindControl("ibtnDown"); if (imgBtn != null) { imgBtn.ImageUrl = "~/images/btnUpUnable.bmp"; imgBtn.Enabled = false;//禁用 } if (imgBtn2 != null) { imgBtn2.ImageUrl = "~/images/btnDownUnable.bmp"; imgBtn2.Enabled = false;//禁用 } } }
| ||
protected void gvSelTchOrderTest_RowCommand(object sender, GridViewCommandEventArgs e) { //…代码 } |