如何取消选中 ASP.NET/VB.NET 上的单选按钮

How to unchecked RadioButton on ASP.NET/VB.NET

我在 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>

例如,我希望当我 select #RB_Type 未选中 #RB_Date 单选按钮时,如果我单击 #RB_Date 则 #RB_Type 按钮未选中。

为此,我在 VB.NET 中添加了以下代码:

If RB_Type.Checked Then

    RB_Date.Checked = False

ElseIf RB_Date.Checked Then

    RB_Type.Checked=False

EndIf

但是在运行时,如果我 select RB_Type 然后单击 RB_Date 然后 RB_Type 将保持 selected 而 RB_Date 将未选中。

我想找到一个解决方案,在此先感谢。

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