我创建了文本框和两个按钮(编辑,删除)。我为每个按钮添加了一些代码来添加eventhandler。
for (int oo = 0; oo < mav.GetCategoriesSalary2(Emplvl.SelectedValue.ToString()).Rows.Count; oo++)
{
TextBox tb1 = new TextBox();
tb1.ID = "textcat" + oo;
tb1.Text = mav.GetCategoriesSalary2(Emplvl.SelectedValue.ToString()).Rows[oo][0].ToString();
tb1.Width = 100;
catresult.Controls.Add(tb1);
Button newButton = new Button();
newButton.ID = "btncatEdit" + oo;
String aa = newButton.ID;
newButton.Text = "Edit";
catresult.Controls.Add(newButton);
Button newButton1 = new Button();
newButton1.ID = "btncatDelete" + oo;
newButton1.Text = "Delete";
catresult.Controls.Add(newButton1);
newButton1.Click += new EventHandler(newButton1_Click);
}
这是事件。
void newButton1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + Emplvl.SelectedValue.ToString() + "');", true);
}
我跑了。当我单击按钮时事件不起作用它只是隐藏在for循环中创建的所有文本框和按钮。我的代码出了什么问题?