![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
后台怎么获取不同Repeater中选中的RadioButton值啊?
在一个页面中有两个Repeater每个Repeater中都有一组RadioButton,用户进入页面后要在不同的Repeater中选中一个RadioButton,最后提交...
在一个页面中有两个Repeater每个Repeater中都有一组RadioButton,用户进入页面后要在不同的Repeater中选中一个RadioButton,最后提交的时候把这两个选中的值插入到数据库,问题是:我该怎么获取这两个不同组中选中的RadioButton值啊?
注:每组的RadioButton数量都是根据数据库中数据动态生成的,代码:第一个Repeater中:
<input type="radio" name="x" id="rx"/>
<asp:Label ID="Label3" runat="server" ><%#Eval("questionnaire_option_id")%></asp:Label>
第二个Repeater中:
<input type="radio" name="y" id="ty"/>
<asp:Label ID="Label6" runat="server" ><%#Eval("questionnaire_option_id")%></asp:Label>
各位哥哥姐姐帮帮忙哦
后台怎么获取这两个不同组中选中的RadioButton值啊? 展开
注:每组的RadioButton数量都是根据数据库中数据动态生成的,代码:第一个Repeater中:
<input type="radio" name="x" id="rx"/>
<asp:Label ID="Label3" runat="server" ><%#Eval("questionnaire_option_id")%></asp:Label>
第二个Repeater中:
<input type="radio" name="y" id="ty"/>
<asp:Label ID="Label6" runat="server" ><%#Eval("questionnaire_option_id")%></asp:Label>
各位哥哥姐姐帮帮忙哦
后台怎么获取这两个不同组中选中的RadioButton值啊? 展开
2个回答
展开全部
只能是遍历RepeaterItem来FindControl找到input 控件并判断所选
伪代码
string selectedVal=string.Empty;
foreach(RepeaterItem item in Repeater1.Items) {
//注意,你需要给Repeater中的input加上runat=server ,并将数据库中的值赋给value属性
HtmlInputRadioButton btn=item.FindControl("rx") as HtmlInputRadioButton;
if (btn.selected) {
//说明被选中,并取出选中的值
selectedVal=btn.value;
}
}
伪代码
string selectedVal=string.Empty;
foreach(RepeaterItem item in Repeater1.Items) {
//注意,你需要给Repeater中的input加上runat=server ,并将数据库中的值赋给value属性
HtmlInputRadioButton btn=item.FindControl("rx") as HtmlInputRadioButton;
if (btn.selected) {
//说明被选中,并取出选中的值
selectedVal=btn.value;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询