1.首先,在UserControl的ascx.cs中,宣告一個事件:
public event EventHandler PublicRowSelecting;
2.再來還是在UserControl的ascx.cs中,讓原本的GridView RowSelecting的事件,執行剛剛宣告的事件PublicRowSelecting:protected void gvMain_RowSelecting(object sender, GridViewSelectEventArgs e) {
this.PublicRowSelecting(this, new EventArgs());
}
3.接下來就是在網頁中使用了,在網頁(Parent Page)的aspx.cs 直接設定事件this.PublicRowSelecting(this, new EventArgs());
}
UserControl1.PublicRowSelecting += new EventHandler(UserControl1_PublicRowSelecting);
4. UserControl1_PublicRowSelecting 是你要執行的程式,這個範例只要 Response.Write就好了protected void UserControl1_PublicRowSelecting(object sender, EventArgs e) {
Response.Write("Test OK");
}
5.大功告成,接下來只要執行到 UserControl中GridView的RowSelecting事件,就會執行UserControl1_PublicRowSelecting了。Response.Write("Test OK");
}
沒有留言:
張貼留言