我有一个在线考试系统,它是用无线电输入的,我的问题是我无法获得所选的输入收音机
<form runat="server"">
<asp:Repeater ID="rptCustomers" runat="server">
<ItemTemplate>
<form>
<div class="question">
<div class="container">
<p class="title">
</p>
<asp:Label CssClass="title" runat="server" Text='<%# Eval("Title") %>'/>
<ul>
<li>
<input type="radio" name="radio" value="1">
<label><%# Eval("r1") %></label>
</li>
<li>
<input type="radio" name="a" value="1">
<label><%# Eval("r2") %></label>
</li>
<li>
<input type="radio" name="a" value="1">
<label ><%# Eval("r3") %></label>
</li>
<li>
<input type="radio" name="a" value="1">
<label ><%# Eval("r4") %></label>
</li>
</ul>
</div>
</div>
</form>
</ItemTemplate>
当我将runat=server添加到输入中时,我无法在代码后面再次获得它们以获得所选的无线电输入?我正在使用c#
发布于 2020-03-23 13:58:04
下面是使用radioButtonList的解决方案:
<div class="row">
<div class="col-md-4">
<h2>Getting started</h2>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem>item1</asp:ListItem>
<asp:ListItem>item2</asp:ListItem>
<asp:ListItem>item3</asp:ListItem>
</asp:RadioButtonList>
</div>
</div>
然后访问所选项的值:
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
String string1 = RadioButtonList1.SelectedItem.Text;
}
不要忘记检查"Enable AutoPostBack",这样您就会注意到在单选按钮之间切换的变化。
https://stackoverflow.com/questions/60821579
复制相似问题