也许我错过了什么!您可以改用事件冒泡。但是 FormView 控件没有处理子控件事件的事件。所以,我们有一些变化。
[System.Web.UI.ToolboxData("<{0}:FormView runat=\"server\" />")]
public class FormView : System.Web.UI.WebControls.FormView
{
private static readonly object _itemClickEvent = new object();
[System.ComponentModel.Category("Action")]
public event EventHandler<System.Web.UI.WebControls.FormViewCommandEventArgs> ItemClick
{
add { base.Events.AddHandler(_itemClickEvent, value); }
remove { base.Events.RemoveHandler(_itemClickEvent, value); }
}
protected virtual void OnItemClick(System.Web.UI.WebControls.FormViewCommandEventArgs e)
{
EventHandler<System.Web.UI.WebControls.FormViewCommandEventArgs> handler = base.Events[_itemClickEvent] as EventHandler<System.Web.UI.WebControls.FormViewCommandEventArgs>;
if (handler != null) handler(this, e);
}
protected override bool OnBubbleEvent(object source, EventArgs e)
{
this.OnItemClick((System.Web.UI.WebControls.FormViewCommandEventArgs)e);
return base.OnBubbleEvent(source, e);
}
}
上面的代码片段演示了我们如何ItemClick
向 FormView 控件添加事件来处理子控件的事件。现在,您应该映射或拖动新的 FormView 控件。