事件委托,当此类(继承自Repeater)加载(Load事件)时,执行DBind方法!!
public class Repeat2: Repeater
{
public void DBind(object sender, EventArgs e)
{
this.DataSource = a;
this.DataBind();
}}
用+=,下面不行!! public class Repeat2: Repeater
{
public void DBind(object sender, EventArgs e)
{
this.Load += new EventHandler(DBind);//这样不行??
this.DataSource = a;
this.DataBind();
}}
那应该怎么写呢,我不想在页面中去执行方法,让他自动绑定这个方法DBind
public class Repeat2: Repeater
{
public void DBind(object sender, EventArgs e)
{
this.DataSource = a;
this.DataBind();
}}
用+=,下面不行!! public class Repeat2: Repeater
{
public void DBind(object sender, EventArgs e)
{
this.Load += new EventHandler(DBind);//这样不行??
this.DataSource = a;
this.DataBind();
}}
那应该怎么写呢,我不想在页面中去执行方法,让他自动绑定这个方法DBind
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//todo: 增加你的代码
} public Class1()
{
this.Load += new EventHandler(Class1_Load);
} void Class1_Load(object sender, EventArgs e)
{
//todo: 增加你的代码
}
}