两个单选按钮ASP.NET C#

Mik*_*ike 32 c# asp.net

我有两个用于公制和美国测量的单选按钮.我加载页面,以便单击度量单选按钮.如何设置这两个按钮,以便在单击US时公制取消,反之亦然?

blo*_*rod 62

为了使其工作,您必须将两个单选按钮的属性GroupName设置为相同的值:

<asp:RadioButton id="rbMetric" runat="server" GroupName="measurementSystem"></asp:RadioButton>
<asp:RadioButton id="rbUS" runat="server" GroupName="measurementSystem"></asp:RadioButton>
Run Code Online (Sandbox Code Playgroud)

就个人而言,我更喜欢使用RadioButtonList:

<asp:RadioButtonList ID="rblMeasurementSystem" runat="server">
    <asp:ListItem Text="Metric" Value="metric" />
    <asp:ListItem Text="US" Value="us" />
</asp:RadioButtonList>
Run Code Online (Sandbox Code Playgroud)


RQD*_*QDQ 19

确保其GroupName属性设置为相同的名称:

<asp:RadioButton GroupName="MeasurementSystem" runat="server" Text="US" />
<asp:RadioButton GroupName="MeasurementSystem" runat="server" Text="Metric" />
Run Code Online (Sandbox Code Playgroud)


ath*_*kar 6

我可以看到这是一个老问题,如果你想把其他HTML放在里面,可以在所有单选按钮中使用具有GroupName属性的单选按钮,并在Text属性集中使用类似图像或你需要的html.

   <asp:RadioButton GroupName="group1" runat="server" ID="paypalrb" Text="<img src='https://www.paypalobjects.com/webstatic/mktg/logo/bdg_secured_by_pp_2line.png' border='0' alt='Secured by PayPal' style='width: 103px; height: 61px; padding:10px;'>" />
Run Code Online (Sandbox Code Playgroud)


小智 2

GroupName两个单选按钮的属性设置为相同的值。您也可以尝试使用 a RadioButtonGroup,它会自动为您执行此操作。