简体   繁体   English

使用后如何保持单选按钮为选中状态?

[英]How can I keep the radio button as checked after using it?

I have on my webpage 6 radiobuttons. 我的网页上有6个单选按钮。 And when you click on one of the buttons, the overview will shown. 当您单击其中一个按钮时,将显示概述。 But the chosen radio button isn't checked. 但是未选中所选的单选按钮。 You see that the button is shown as checked for a while. 您会看到该按钮显示为选中状态一段时间。 But than as the other ones it will be unchecked again. 但是,与其他选项相比,它将再次被取消选中。

How can I keep it checked? 如何保持检查状态?

The view: 风景:

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" >
        <% using (Html.BeginForm("Overige_Statistieken", "Hitdossier", 

        FormMethod.Post, new { id = "frmStatistieken" })) %>
            <% { %>
                <table>
                    <tr>
                        <th class="hitlijst_editie">Selecteer overzicht:</th>
                    </tr>
                    <tr>
                        <td>
                        <%= Html.RadioButton("Overzicht", "1", new
                            {
                                @onclick = "document.getElementById('frmStatistieken').submit();"
                            }) %> Overzicht Alle Nummer 1 hits per week
                        </td>
                    </tr>
                    <tr>
                        <td>
                        <%= Html.RadioButton("Overzicht", "2", new
                            {
                                @onclick = "document.getElementById('frmStatistieken').submit();"
                            })%> Overzicht Alle Tips van de week
                        </td>
                    </tr>
...
        </table>
        <br />
        <br />
        <div>
             <%= Html.Action("Overige_StatistiekenLijst", new { AID_Overzicht = ViewBag.ID_Overzicht })%> <br />   
        </div>
    <% } %>
</asp:Content>

... and this is the controller: ...这是控制器:

public ActionResult Overige_Statistieken(string AID_Overzicht = "1")
{
    ViewBag.ID_Overzicht = AID_Overzicht;
    return View();
}

[HttpPost]
public ActionResult Overige_Statistieken(FormCollection ACollection)
{
    string sID_Overzicht = ACollection["Overzicht"].ToString();
    return Overige_Statistieken(sID_Overzicht);
}

public ActionResult Overige_StatistiekenLijst(string AID_Overzicht)
{
    ViewBag.ID_Overzicht = AID_Overzicht;

    ReadOverigeStatistieken(AID_Overzicht);
    return View(_ListOverzichtModel);
}

There's an overload method that will allow you to set the initial state of the radio button, using the isChecked parameter (third argument). 有一个重载方法,允许您使用isChecked参数(第三个参数)设置单选按钮的初始状态。

<%= Html.RadioButton("Overzicht", "1",  (int)ViewBag.ID_Overzicht==1,  new
      {
          @onclick = "document.getElementById('frmStatistieken').submit();"
      }) %>

The following was added to your code. 以下内容已添加到您的代码中。 Do that same thing to all your radio buttons paying attention to the value (ie 1) you will check against. 对所有单选按钮执行相同的操作,注意要检查的值(即1)。

ViewBag.ID_Overzicht==1

暂无
暂无

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

相关问题 如何将网格中的单选按钮设置为“选中” - How can I set a radio button in a grid to “checked” 如何在不删除文本值的情况下“禁用”单选按钮,以及是否选中它 - How can I "disable" a radio button, without removing the text value, and whether it's checked or not 如果选中单选按钮,如何为更新面板设置visible true? - How can I set visible true for update Panel if Radio Button Checked? 如果选中了特定的单选按钮,如何更改标签的名称? - How do I change the name of a label if a specific radio button is checked? 如何从分组框中选中哪个单选按钮? - How do I get which radio button is checked from a groupbox? 单击按钮以进行更新后如何保持复选框处于选中状态 - How to keep check box checked after button click for update 如何在不使用GroupBox的情况下为单选按钮提供值并确定选定的单选按钮 - How can I give a radio button a value and determine the selected radio button without using a GroupBox 如何使用jquery获取选定的asp单选按钮? - how can i get the selected asp radio button using jquery? 每当我在UWP中将选项从“是”更改为“否”时,如何从列表中替换选中的单选按钮的值? - How can i replace the value of checked radio button from a LIST whenever i change my option from yes to no vice versa in UWP 如何获取单选按钮值并清除表中选中的单选按钮 - How to get radio button value and clear checked radio button in table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM