日期:2014-05-20  浏览次数:20499 次

取Panel里的控件问题。
int   num=1;
while(reader.Read())
{
RadioButtonList   rbtnList=new   RadioButtonList();
rbtnList.ID= "rbtnList "+num.ToString();
rbtnList.Items.Add( "A.   "+Server.HtmlEncode(reader[ "testAns1 "].ToString()));
rbtnList.Items.Add( "B.   "+Server.HtmlEncode(reader[ "testAns2 "].ToString()));
rbtnList.Items.Add( "C.   "+Server.HtmlEncode(reader[ "testAns3 "].ToString()));
rbtnList.Items.Add( "D.   "+Server.HtmlEncode(reader[ "testAns4 "].ToString()));
num++;
}
                                   

这样在Panel里建立的控件,
RadioButtonList   list;
  list   =   (RadioButtonList)Panel1.FindControl( "rbtnList "   +   i.ToString());

list为什么是Null

------解决方案--------------------
RadioButtonList list;
list = (RadioButtonList)FindControl( "rbtnList " + i.ToString());

------解决方案--------------------
这个问题,我在半年前也遇到过,后来改用FormView了.行.