高手请进!!!动态添加控件并绑定事件问题
小弟(菜鸟)打算写一个用户控件,遇到了动态添加控件事件绑定的问题:
用户控件代码如下:
aspx 页:
<asp:Table ID= "tb_SC " runat= "server ">
<asp:TableHeaderRow ID= "th_01 " runat= "server " Width= "100% ">
<asp:TableCell HorizontalAlign= "Center " ID= "tc_01 " runat= "server ">
</asp:TableCell>
</asp:TableHeaderRow>
<asp:TableRow ID= "tr_01 " runat= "server " Width= "100% "> </asp:TableRow>
</asp:Table>
cs 页:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Create();
}
}
private void Create()
{
//动态生成签字位名称、内容及按钮
for (int i = 0; i < dt.Rows.Count; i++)
{
Button btn_Yes = new Button();
btn_Yes.ID = "btn_Yes_ " + i.ToString();
btn_Yes.Text = "Yes ";
btn_Yes.Click += new EventHandler(btn_Yes_Click);
//不同意按钮
Button btn_No = new Button();
btn_No.ID = "btn_No_ " + i.ToString();
btn_No.Text = "No ";
btn_No.Click += new EventHandler(btn_No_Click);
TableCell tc2 = new TableCell();
tc2.Controls.Add(btn_Yes);
tc2.Controls.Add(btn_No);
//将两列添加到行中
tr_01.Controls.Add(tc1);
tr_01.Controls.Add(tc2);
}
}
private void btn_Yes_Click(Object sender, EventArgs e)
{
//事件处理
}
private void btn_No_Click(Object sender, EventArgs e)
{
//事件处理
}
如何才能把按钮单击事件绑定到我动态添加的按钮上?请指教!!!
在调用用户控件事激发呀?