我的代码如下。我有一个问题,我只想选择一个rdbtn5或任何一个单选项列表项。但它可以选择两者。请建议。
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="70%" style="padding-left:10px; text-decoration-color:white">
<div class="content" style="display: inline-block !important;">
<asp:RadioButton ForeColor="White" ID="rdContribute" AutoPostBack="true" OnCheckedChanged="rdContribute_CheckedChanged" Text="abc"<br/> GroupName="RadioGroup1" runat="server" /><!--onchange="Monthly()" -->
<div style="display:block;margin-left:10px;" id="dvrdList">
<asp:RadioButtonList ID="rdlist" ForeColor="White" GroupName="Selected1" runat="server">
<asp:ListItem Text="Rs.100/month(Rs.1200/Year)" Value="100" name="abc" Selected="True"></asp:ListItem>
<asp:ListItem Text="R.250/month(Rs.3000/Year)" Value="250" name="abc"></asp:ListItem>
<asp:ListItem Text="Rs.500/month(Rs.6000/Year)" Value="500" name="abc"></asp:ListItem>
<asp:ListItem Text="Rs.1000/month(Rs.12000/Year)" Value="1000" name="abc"></asp:ListItem>
<asp:ListItem Text="Rs.5000/month(Rs.60000/Year)" Value="5000" name="abc"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButton runat="server" ID="rdbtn5" name="abc" AutoPostBack="true" OnCheckedChanged="rdContribute_CheckedChanged" GroupName="Selected1"/><asp:TextBox ID="tbGreater" runat="server" onkeypress="return isNumberKey(event)" CausesValidation="true" Enabled="false"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" Type="Integer" MinimumValue="1000" MaximumValue="1000000" ControlToValidate="tbGreater" runat="server" ErrorMessage="Enter digits greater than 1000"></asp:RangeValidator>
</div>
<asp:RadioButton ForeColor="White" ID="rdNo" AutoPostBack="true" Text="I do not wish to make a contribution" OnCheckedChanged="rdNo_CheckedChanged" GroupName="RadioGroup1" runat="server" />
</div>
</td>
</tr>
<tr>
<td>
<asp:RadioButton ForeColor="White" ID="rdReminder" AutoPostBack="true" name="rdReminder" Visible="false" OnCheckedChanged="rdReminder_CheckedChanged" Text="def" GroupName="RadioGroup1" runat="server" />
</td>
</table>
答案 0 :(得分:0)
将其添加到RadioButtonList OnSelectedIndexChanged
。
protected void rdlist_CheckedChanged(object sender, EventArgs e)
{
//uncheck all checkboxes
rdbtn1.Checked = false;
rdbtn2.Checked = false;
rdbtn3.Checked = false;
rdbtn4.Checked = false;
rdbtn5.Checked = false;
}
将此事件添加到所有其他RadioButtons
protected void globalRadio_SelectedIndexChanged(object sender, EventArgs e)
{
//uncheck all checkboxes
rdbtn1.Checked = false;
rdbtn2.Checked = false;
rdbtn3.Checked = false;
rdbtn4.Checked = false;
rdbtn5.Checked = false;
//uncheck all checkboxes in the list
foreach (ListItem listItem in rdlist.Items)
{
listItem.Selected = false;
}
//re-check the clicked radiobutton
RadioButton rb = sender as RadioButton;
rb.Checked = true;
}