C# ASP.NET Webforms中的Foreach单选按钮
我想申请一张申请表。在其中一个视图中,我有几个单选按钮,如下所示--C# ASP.NET Webforms中的Foreach单选按钮,c#,asp.net,webforms,C#,Asp.net,Webforms,我想申请一张申请表。在其中一个视图中,我有几个单选按钮,如下所示-- Loop和LINQ版本,但问题是我的RadioButton控件不直接在页面中。让我详细说明一下- 首先,我在一个页面中有多个视图- 多视图包含多个视图- 最后是内部视图,我有单选按钮控件- 现在,我的目标是获取所有选中的单选按钮的值,该按钮使用上面的div布局 任何帮助和指导都将不胜感激!谢谢 您必须将您的单选按钮作为RadioButtonList的子项,然后在RadioButtonList项上的foreach循环中迭
Loop
和LINQ
版本,但问题是我的RadioButton控件不直接在页面中。让我详细说明一下-
首先,我在一个页面中有多个视图-
多视图包含多个视图-
最后是内部视图,我有单选按钮
控件-
现在,我的目标是获取所有选中的单选按钮的值,该按钮使用上面的div
布局
任何帮助和指导都将不胜感激!谢谢 您必须将您的单选按钮作为RadioButtonList的子项,然后在RadioButtonList项上的foreach循环中迭代。您必须将您的单选按钮作为RadioButtonList的子项,然后在RadioButtonList项上的foreach循环中迭代。为什么不使用RadioButtonList
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
您还可以在代码隐藏中向RadioButtonList添加项目
string value = RadioButtonList1.SelectedValue;
RadioButtonList1.Items.Insert(0, new ListItem("Yes", "1", true));
RadioButtonList1.Items.Insert(1, new ListItem("No", "0", true));
为什么不使用RadioButtonList
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
您还可以在代码隐藏中向RadioButtonList添加项目
string value = RadioButtonList1.SelectedValue;
RadioButtonList1.Items.Insert(0, new ListItem("Yes", "1", true));
RadioButtonList1.Items.Insert(1, new ListItem("No", "0", true));