假设有一个button1.   button1_click()事件中,我通过循环生成了一些radiobutton控件,这是用来在线测试用的,就是说一个题有四个选项,那我需要四个radiobutton,而题目是很多个,我通过下面的方式生成radiobutton
for (int i=0;i<sum;i++) //sum为总共要产生的题目数量
{
  for (int j=0;j<4;j++)
  {
  RadioButton rb=new RadioButton();
  rb.ID=stirng.Format("rb{0}",i);
  Panel.Controls.Add(rb);
  
  }
}然后有一个button2.   用来在测试完之后点击交卷这样子,然后在button2_click()事件中怎么获取相应的radiobutton的值??
被这个问题困扰很多天了,相当痛苦啊,拜托看见帖子的朋友帮忙指点一下,感激不尽。

解决方案 »

  1.   

    是 text 属性 还是 chenced 属性?
      

  2.   

    public static string GetChildControl(Control panel)
            {
              string raid_button_name = "";
              string raid_button_value = "";
              if (panel.HasChildren)
              {
                foreach (Control ctl in panel.Controls)
                {
                  if (ctl.GetType().ToString() == "System.Windows.Forms.RadioButton")
                  {
                    if (((System.Windows.Forms.RadioButton)ctl).Checked == true)
                    {
                      raid_button_name = ((System.Windows.Forms.RadioButton)ctl).Text;
                      raid_button_value = ((System.Windows.Forms.RadioButton)ctl).Checked.ToString();
                    }
                            
                  }
                  GetChildControl(ctl);
                }
              }
              return raid_button_name+"-"+raid_button_value;
            }