日期:2014-05-17 浏览次数:20892 次
private void createBtn()
{
List<BtnFun> lBtn;
using (PTE p = new PTE())
{
lBtn = (from btn in p.BtnFun select btn).ToList<BtnFun>();
}
TableRow tr = new TableRow();
foreach (BtnFun b in lBtn)
{
Button btn = new Button();
btn.ID = b.BtnID;
btn.Text = b.BtnText;
btn.Visible = (bool)b.BtnVisible;
// 这里如何把变量当方法绑定到Click事件中
//btn.Click += new EventHandler(b.btndelegate);
TableCell tc = new TableCell();
tc.Controls.Add(btn);
tr.Cells.Add(tc);
}
tbtn.Rows.Add(tr);
}
{
...
btn.Click += GetHandler(b.btndelegate);
}
private EventHandler GetHandler(string cmd)
{
switch(cmd.ToLower())
{
case "add": return this.add;
case "alter": return this.alter;
case "check": return this.check;
case "del": return this.del;
}
return null;
}
btn.Click += (EventHandler)