一个页面有10个RadioButtonList控件,id从RadioButtonList1到RadioButtonList10for (int k = 1; k<=10; k++)
        {
            RadioButtonList singleRadioList = (RadioButtonList)this.FindControl("RadioButtonList" + k.ToString());
            
        }执行之后,singleRadioList 为null是怎么回事

解决方案 »

  1.   

    這樣当然会没有用,你的RadioButtonList 在页面上程现的是RadioButtonList1_0  RadioButtonList1_2 ......RadioButtonList10_0
    你用FindControl是查询不到的.
    你还是想想办法得到Html的Radio吧
      

  2.   

    看你的写法,应该是正确的,但必须保证RadioButtonList都在this上,而不在其他控件上
      

  3.   

    foreach(Control control in this.Page.Controls)
    {
         if(control is RadioButtonList)
    {
           //do somethings
    }
    }
      

  4.   

    你可以通过遍历控件的方式,先把readiolist强转,然后再判断属性,通过id获取