再次贴出我的部分代码。
这里是动态生成控件的代码
protected void btnSubmit_Click(object sender, EventArgs e)
{
Table table = new Table();
table.ID = "tableSeat";
TableRow tablerow;
TableCell tablecell;
TextBox txt;
Label lbl;
int row = Convert.ToInt32(txtRow.Text.ToString());
for (int i = 1; i <= row; i++)
{
tablerow = new TableRow();
tablecell = new TableCell();
txt = new TextBox();
lbl = new Label();
lbl.ID = "Lable" + i.ToString();
lbl.Text = "第" + i.ToString() + "排的座位数为:";
tablecell.Controls.Add(lbl);
tablerow.Cells.Add(tablecell);
tablecell = new TableCell();
txt.ID = "txtSeatOf" + i.ToString();
tablecell.Controls.Add(txt);
tablerow.Cells.Add(tablecell);
table.Rows.Add(tablerow);
}
MyPanel.Controls.Add(table);
btnSave.Enabled = true;
}
这里是测试读取数据的代码,每次FIND控件都为NULL
protected void btnSave_Click(object sender, EventArgs e)
{
Table tableTest = new Table();
TextBox txt1 = new TextBox();
tableTest = MyPanel.FindControl("tableSeat") as Table;
txt1 = tableTest.FindControl("txtSeatOf1") as TextBox;
string str = txt1.Text;
}
我也想设置RUNAT 可是我后台直接NEW出来的控件,没有办法设置RUNAT这个属性。不知道为什么。