页面上要多个单选按钮 但名字又不相同 如何在选择时 在另一个文本框获得选中的单选按钮的值。且这些单选按钮不是直接拖上页面的 而是在程序运行时 加载的。

解决方案 »

  1.   

    试试Request.Form["单选按钮的名字"];
      

  2.   

    自定义控件,单选按钮是RadioButton?
    请问你要的值是它的文本,还是选它后,会返回一个特定的值?
      

  3.   

    加按钮的时候同时添加autopostback=true
    还有就是添加事件checkedchange的委托代码
      

  4.   

    就是注册checkedchange这个事件,然后分配事件的方法
      

  5.   

    按钮就对应一个动作,所以,需要 添加事件checkedchange的委托。
    你在动态创建RedioButton时,就可以用一个数组来对其进行管理。这样,当点击某个按钮时,就可以从数据中找出来。    System.Collections.ArrayList listRdoBtn = new System.Collections.ArrayList();
        ...    System.Windows.Forms.RadioButton rdo1 = new System.Windows.Forms.RadioButton();
        rdo1.Text = "radio button1";
        rdo1.CheckedChanged += new EventHandler(rdo1_CheckedChanged);
        listRdoBtn.Add(rdo1);    System.Windows.Forms.RadioButton rdo2 = new System.Windows.Forms.RadioButton();
        rdo2.Text = "radio button2";
        rdo2.CheckedChanged += new EventHandler(rdo2_CheckedChanged);
        listRdoBtn.Add(rdo2);    System.Windows.Forms.RadioButton rdo3 = new System.Windows.Forms.RadioButton();
        rdo3.Text = "radio button3";
        rdo3.CheckedChanged += new EventHandler(rdo3_CheckedChanged);
        listRdoBtn.Add(rdo3);        private void rdo1_CheckedChanged(object sender, EventArgs e)
            {
                string strText = ((System.Windows.Forms.RadioButton)sender).Text;
                // Show text in the text editor...
                // ...
            }
      

  6.   

    顶,为checkedchange事件编写委托代码即可。(我习惯把变量声明成public的,这样可以全局调用)