动态生成Button,事件该怎么写..
有一个根据数据多少动态生成的表格,表格中有一列(联系电话)是初次加载时不显示的..
在该列中有一个Button,点击显示联系电话..(Button也是随表格动态添加的.)
现在遇到的问题是:添加的Button按钮添加事件后点击每次都会刷新页面,刷新后动态生成表格不见了..
下面是代码://动态添加第六列..
HtmlTableCell htr1_c6 = new HtmlTableCell();
Panel panel1 = new Panel();
panel1.Visible = true;
Button bt_01 = new Button();
bt_01.Command += new CommandEventHandler(this.bt_01_Click);
bt_01.Text = "显示";
bt_01.CommandName = "bt_01_Click";
bt_01.CommandArgument = i.ToString();
panel1.Controls.Add(bt_01);
Panel panel2 = new Panel();
panel2.Visible = false;
Label lb1 = new Label();
lb1.Text = ds.Tables[0].Rows[i]["LXDH"].ToString().Trim();
Button bt_02 = new Button();
bt_02.Command += new CommandEventHandler(this.bt_02_Click);
bt_02.Text = "隐藏";
bt_02.CommandArgument = i.ToString();
panel2.Controls.Add(lb1);
panel2.Controls.Add(bt_02);
htr1_c6.Controls.Add(panel1);
htr1_c6.Controls.Add(panel2);
htr1.Controls.Add(htr1_c6);
ilist.Rows.Add(htr1);
protected void bt_01_Click(object sender, EventArgs e)
{
//获得传递的参数:按钮所在的表格的行数..
int i = Convert.ToInt32(((Button)sender).CommandArgument);
Response.Write("aaaaaaaaaaa");//用这个测试也没有aaaaaaaaaaa输出在网页上..
((Panel)ilist.Rows[i].Cells[5].Controls[0]).Visible = false;
((Panel)ilist.Rows[i].Cells[5].Controls[1]).Visible = true;
}
protected void bt_02_Click(object sender, EventArgs e)
{
//获得传递的参数:按钮所在的表格的行数