为什么会找不到radiobuttonlist呢 很急啊
点击一个button产生了10个题,然后答案是ABCD 可是点击提交的button之后为什么找不到radiobuttonlist呢???protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
RadioButtonList rbl = new RadioButtonList();
rbl.ID = i.ToString();
rbl.RepeatDirection = RepeatDirection.Horizontal;
for (int j = 0; j < 4; j++)
{
ListItem li = new ListItem();
switch (j)
{
case 0:
li.Text = "A";
li.Value = "A";
break;
case 1:
li.Text = "B";
li.Value = "B";
break;
case 2:
li.Text = "C";
li.Value = "C";
break;
case 3:
li.Text = "D";
li.Value = "D";
break;
}
rbl.Items.Add(li);
}
Panel1.Controls.Add(rbl);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
RadioButtonList list = (RadioButtonList)Panel1.FindControl(i.ToString());
if (list == null)
Response.Write("为空");
else
Response.Write("不为空");
}
}
每次输出来的都是“为空为空为空”
这是为什么 为什么