朋友们帮我看看,遇到个抢手的问题 动态的生成几个空间,可是怎么动态的给控件添加一些事件呢,比如说我动态的生成一个dropDownList,怎么给它添加事件呢?
下面是我写的代码:
private void AddQuery(DropDownList drop)
{
if (drop.Text != "请选择")
{
Table tt = new Table();
TableCell cell1 = new TableCell();
TableCell cell2 = new TableCell();
TableCell cell3 = new TableCell();
TableCell cell4 = new TableCell();
DropDownList drop1 = new DropDownList();
drop1.ID = "drop1";
drop1.Items.Add("请选择");
drop1.Items.Add("姓名");
drop1.Items.Add("年龄");
drop1.Items.Add("性别");
cell1.Controls.Add(drop1);
DropDownList drop2 = new DropDownList();
drop2.ID = "drop2";
drop2.Items.Add("请选择");
drop2.Items.Add("大于");
drop2.Items.Add("等于");
drop2.Items.Add("小于");
cell2.Controls.Add(drop2);
TextBox tb1 = new TextBox();
tb1.ID = "tb1";
cell3.Controls.Add(tb1);
DropDownList drop3 = new DropDownList();
drop3.ID = "drop3";
drop3.Items.Add("请选择");
drop3.Items.Add("并且");
drop3.Items.Add("或者");
drop3.AutoPostBack = true;
??//想给drop3添加SelectedIndexChanged的事件,该事件也调用这个方法
cell4.Controls.Add(drop3);
TableRow row = new TableRow();
row.Cells.Add(cell1);
row.Cells.Add(cell2);
row.Cells.Add(cell3);
row.Cells.Add(cell4);
tt.Rows.Add(row);
Panel1.Controls.Add(tt);
}
真没想到方法,请大侠指教拉 谢谢
[此贴子已经被作者于2007-1-23 14:56:03编辑过]