我有一個與Page_Init,Page_Load事件有關的問題,當我點擊我的頁面內的Gridview時,有2次連線。事件有線連接2次
我檢查了AutoEventWireup,但aspx和ascx是正確的(false和OnInit覆蓋)。
來自Gridview的事件在Page_Init中設置,但如果它在Page_Load中則是相同的行爲。我爲2個Gridviews使用相同的事件。
有些想法可以幫助我嗎?
這裏我的代碼
protected override void OnInit(EventArgs e)
{
instance = (IServiceActivity)InterfaceRepository.GetService(typeof(ServiceActivity));
this.Load += new EventHandler(Page_Load);
this.CollectionGridView1.RowDeleting += new GridViewDeleteEventHandler(CollectionGridView1_RowDeleting);
this.CollectionGridView1.RowDataBound += new GridViewRowEventHandler(CollectionGridView1_RowDataBound);
this.CollectionGridView1.RowEditing += new GridViewEditEventHandler(CollectionGridView1_RowEditing);
this.CollectionGridView1.Sorting += new GridViewSortEventHandler(CollectionGridView1_Sorting);
this.CollectionGridView1.PageIndexChanging += new GridViewPageEventHandler(CollectionGridView1_PageIndexChanging);
this.CollectionGridView2.RowDeleting += new GridViewDeleteEventHandler(CollectionGridView1_RowDeleting);
this.CollectionGridView2.RowDataBound += new GridViewRowEventHandler(CollectionGridView1_RowDataBound);
this.CollectionGridView2.RowEditing += new GridViewEditEventHandler(CollectionGridView1_RowEditing);
this.CollectionGridView2.Sorting += new GridViewSortEventHandler(CollectionGridView1_Sorting);
this.CollectionGridView2.PageIndexChanging += new GridViewPageEventHandler(CollectionGridView1_PageIndexChanging);
base.OnInit(e);
}
protected void CollectionGridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
CollectionGridView cgv = (CollectionGridView)sender;
cgv.SelectedIndex = e.RowIndex;
CvrActivity cvrAct = new CvrActivity();
cvrAct = instance.GetActivityById(long.Parse(cgv.SelectedDataKey.Value.ToString()));
if (cvrAct != null)
{
//DELETE
}
}
protected void CollectionGridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
CollectionGridView cgv = (CollectionGridView)sender;
cgv.SelectedIndex = e.NewEditIndex;
base.Modify(long.Parse(cgv.SelectedDataKey.Value.ToString()));
}
最後一個樣品,問題是CommandField中,當它在按鈕類型=「形象」,編輯或刪除觸發2次。
那麼如何使用ButtonType和Image?
如果我評論,沒有事件發生 – 2010-01-22 09:46:38