简体   繁体   English

需要帮助将单选按钮从 html 转换为 aspx

[英]need help converting radio button from html to aspx

Can anyone help me with converting this into aspx?谁能帮我把它转换成aspx? I tried adding asp:radiobutton and runat='server' but the radio button will not be ticked.我尝试添加 asp:radiobutton 和 runat='server' 但不会勾选单选按钮。

<div class="col-12 pt-2 ps-3">Temperature</div>
<div class="col-lg-4 col-6">
   <input type="radio" class="btn-check" name="options" id="temperature_0" autocomplete="off">
   <label class="btn btn-secondary w-100 p-lg-3 p-3" for="temperature_0">below 36&deg;C</label>
</div>
                
<div class="col-lg-4 col-6">
   <input type="radio" class="btn-check" name="options" id="temperature_1" autocomplete="off" checked>
   <label class="btn btn-secondary w-100 p-lg-3 p-3" for="temperature_1">36&deg;C - 37&deg;C</label>
</div>
                
<div class="col-lg-4 col-6 pt-lg-0 pt-2">
   <input type="radio" class="btn-check" name="options" id="temperature_3" autocomplete="off">
   <label class="btn btn-secondary w-100 p-lg-3 p-3" for="temperature_3">above 37&deg;C</label>
</div>

Well, you can and could drop in that markup as you have - it would work, but then to wire up the event code behind, - not all that great.好吧,您可以并且可以按照您的方式放入该标记 - 它会起作用,但随后将事件代码连接到后面, - 并不是那么好。

In place of multiple inputs (as radio), and using the same ID?代替多个输入(作为收音机),并使用相同的 ID? That does give you a single choice.这确实给了你一个选择。 But in asp.net, better to use what we call a RadioButton list.但是在 asp.net 中,最好使用我们所说的 RadioButton 列表。

So, I would suggest this approach:所以,我建议这种方法:

      <style>
            .MyRadio label
                {
                  margin-left: 8px;
                  margin-right:20px;
                }
        </style>

        <asp:RadioButtonList ID="RadioButtonList1" runat="server" cssclass="MyRadio" RepeatDirection="Horizontal"
            >
            <asp:ListItem>below 36&deg;C</asp:ListItem>
            <asp:ListItem Selected="True">36&deg;C - 37&deg;C</asp:ListItem>
            <asp:ListItem>above 37&deg;C</asp:ListItem>
        </asp:RadioButtonList>

And you get this:你得到这个:

在此处输入图像描述

You can set the list to be horizontal, or vertical - your choice.您可以将列表设置为水平或垂直 - 您的选择。 Ver vertical, just remove the Horizontal tag, and thus this: Ver垂直,只需删除Horizontal标签,因此:

        <asp:RadioButtonList ID="RadioButtonList1" runat="server" cssclass="MyRadio">
            <asp:ListItem>below 36&deg;C</asp:ListItem>
            <asp:ListItem Selected="True">36&deg;C - 37&deg;C</asp:ListItem>
            <asp:ListItem>above 37&deg;C</asp:ListItem>
        </asp:RadioButtonList>

Will render as this:将呈现为:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM