[英]How to override custom Control Event?
我創建了一個繼承自GridView的自定義gridView類。
public class CustomGridView : GridView {}
它在footerRow中添加了一個文本框,我想直接在我的頁面中管理此文本框的已更改事件,而不是在類中。
就像是 :
public override void txtSearch_TextChanged(object sender, EventArgs e) { }
我怎么能這樣做?
您必須向CustomGridView
添加一個新事件,並在文本框的TextChanged
事件的處理程序中TextChanged
事件。
所以,在CustomGridView
:
public event EventHandler FooterTextChanged;
private void RaiseFooterTextChanged()
{
var handler = FooterTextChanged;
if(handler == null)
return;
handler(this, EventArgs.Empty);
}
public override void txtSearch_TextChanged(object sender, EventArgs e)
{
RaiseFooterTextChanged();
}
在使用CustomGridView
的類中:
customGridView.FooterTextChanged += OnGridFooterTextChanged;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.