怎么获得动态生成控件的值
代码如下
int number = int.Parse(txt_number.Text.ToString());
HtmlTable tb = new HtmlTable();
for (int i = 1; i <= number; i++)
{
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell td1 = new HtmlTableCell();
HtmlTableCell td2 = new HtmlTableCell();
HtmlTableCell td3 = new HtmlTableCell();
Button bt = new Button();
td1.Attributes.Add("background", "../Images/银条.gif");
td2.Attributes.Add("background", "../Images/银条.gif");
td3.Attributes.Add("background", "../Images/银条.gif");
tr.Height = "33px";
Label lb1 = new Label();
Label lb2 = new Label();
TextBox tb1 = new TextBox();
tb.Width = "100%";
TextBox tb2 = new TextBox();
lb1.Text = "字段名";
lb1.ID = "lb_name" + i;
lb2.Text = "长度";
lb2.ID = "lb_leng" + i;
tb1.ID = "Field" + i;
tb2.ID = "Field_leng" + i;
tb2.Text = "1000";
bt.Text = "删除此行";
bt.Command += new CommandEventHandler(this.onbutton);
td1.Controls.Add(lb1);
td1.Controls.Add(tb1);
td2.Controls.Add(lb2);
td2.Controls.Add(tb2);
td3.Controls.Add(bt);
bt.ID = "bt_delete" + i;
tr.Cells.Add(td1);
tr.Cells.Add(td2);
tr.Cells.Add(td3);
tb.Rows.Add(tr);
}
Page.Controls.Add(tb);
Control dir = Page.FindControl("dongtai");
dir.Controls.Add(tb);
最后就是怎么在cs代码里通过一个事件,获得动态生成的文本框里的值,先谢谢各位了,
我试过的方法也贴下来吧
Control dir = Page.FindControl("dongtai");
for (int i = 1; i <= number; i++)
{
//TextBox Field[i]=new TextBox();
// (Field+i)
// ImageButton1.Attributes.Add("onclick", "document.getElementById('hdnMyTextBox').value=document.getElementById('Field'" + i + "').value;return true;");
//TextBox tb = (TextBox)(dir.FindControl("Field" + i));// + " Nvarchar(" + ((TextBox)(Page.FindControl("Field_leng1"))).Text + "),";
//Response.Write(tb.Text);
}
这些都不行