如题 代码如下
- C# code
//添加代码 Panel1.Controls.Clear(); for (int i = 0; i < Convert.ToInt32(DlPerson.SelectedValue); i++) { Panel1.Controls.Add(new TextBox() { Text="姓名"+i.ToString(), ID="lbl"+i.ToString() }); } //遍历代码 for (int i = 0; i < Panel1.Controls.Count; i++) { if (Panel1.Controls[i] is TextBox) { TextBox tb = Panel1.Controls[i] as TextBox; guestList.Add(new Guest() { Name = tb.Text, RoomNumber = i.ToString() }); } }
取出来全是null ,晕了,求高手解决
------解决方案--------------------------------------------------------
Panel1.Controls.Count; 这个是0么?
//遍历代码
for (int i = 0; i < Panel1.Controls.Count; i++)
{
if (Panel1.Controls[i].Name="lbl"+i)
{
}
}
------解决方案--------------------------------------------------------
调试啊,这还问什么呢,看看Panel1上是否有控件