问题描述
for(inti=0;i<dch.Count;i++){RadioButtonListrad=(RadioButtonList)(Panel1.FindControl(dch[i].ToString()));if(rad.SelectedItem.Selected==true){Response.Write(rad.SelectedItem);}dch里面放的是之前动态生成的所有的radiobuttonlistrad的ID他说我未将对象引用到实例,为什么呢,我想取出radiobuttonlist几个值
解决方案
解决方案二:
RadioButtonList是用来做单选用途的吧。
解决方案三:
页面回发了以后,你动态创建的RadioButtonList就没了
解决方案四:
那我该如何取出radionbotton的值呢
解决方案五:
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;publicpartialclass_Default:System.Web.UI.Page{RadioButtonList[]dch=newRadioButtonList[4];protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){}for(inti=0;i<4;++i){RadioButtonListrdl=newRadioButtonList();rdl.ID="rdl"+i.ToString();rdl.RepeatDirection=RepeatDirection.Horizontal;for(intj=0;j<3;++j){rdl.Items.Add(newListItem(j.ToString()));}dch[i]=rdl;form1.Controls.Add(rdl);}}protectedvoidButton1_Click(objectsender,EventArgse){for(inti=0;i<dch.Length;i++){RadioButtonListrad=(RadioButtonList)(this.FindControl(dch[i].ID.ToString()));if(rad.SelectedValue!=null){Response.Write(rad.SelectedItem);}}}}把动态创建控件的代码放到if(!IsPostBack)外