RadioButtonList是用来做单选用途的吧。

解决方案 »

  1.   

    页面回发了以后,你动态创建的RadioButtonList就没了
      

  2.   

    那我该如何取出radionbotton的值 呢
      

  3.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page 
    {
        RadioButtonList[] dch = new RadioButtonList[4];
        protected void Page_Load(object sender, EventArgs e)
        {        if (!IsPostBack)
            {
               
            } 
            for (int i = 0; i < 4; ++i)
                {
                    RadioButtonList rdl = new RadioButtonList();
                    rdl.ID = "rdl" + i.ToString();
                    rdl.RepeatDirection = RepeatDirection.Horizontal;
                    for (int j = 0; j < 3; ++j)
                    {
                        rdl.Items.Add(new ListItem(j.ToString()));
                    }
                    dch[i] = rdl;
                    form1.Controls.Add(rdl);
                }    }
        protected void Button1_Click(object sender, EventArgs e)
        {        for (int i = 0; i < dch.Length; i++)
            {
                RadioButtonList rad = (RadioButtonList)(this.FindControl(dch[i].ID.ToString()));
                if (rad.SelectedValue != null)
                {
                    Response.Write(rad.SelectedItem);
                }
            }
        }    
    }
    把动态创建控件的代码放到 if (!IsPostBack) 外