如何在ASP.NET/VB.NET上取消选中RadioButton



我在ASP.Net中有两个单选按钮,如下所示:

<dx:ASPxRadioButton ID="RB_Type" runat="server" AutoPostBack="true" Theme="Office365" Text="Type of media" Font-Size="Medium"></dx:ASPxRadioButton>
<dx:ASPxRadioButton ID="RB_Date" runat="server" Theme="Office365" AutoPostBack="true" Text="Date" Font-Size="Medium" ClientInstanceName="RB_Date"></dx:ASPxRadioButton>

例如,我希望当我选择#RB_Type时,#RB_Date单选按钮未选中,然后如果我单击#RB_Date,#RB_TType按钮未选中。

为此,我在VB.NET中有以下代码:

If RB_Type.Checked Then
RB_Date.Checked = False
ElseIf RB_Date.Checked Then
RB_Type.Checked=False
EndIf

但在运行时,如果我选择RB_Type,然后单击RB_Date,则RB_Type将保持选中状态,RB_Date将取消选中。

我想找到一个解决方案,提前谢谢。

您根本不需要任何代码。对于那些要作为组工作的控件,应该将RadioButtonsGroupName属性设置为相同的值。然后,该组将本质上是互斥的,即选中组中的一个将自动取消选中任何其他组。

最新更新