【问题标题】:RadioButtonList vs CheckBoxRadioButtonList 与 CheckBox
【发布时间】:2013-08-08 22:59:39
【问题描述】:

我正在使用 ASP.NET 创建一个 Web 应用程序表单。以前我使用复选框来接受具有 3 个选项的用户输入:添加、编辑、删除。

使用一些服务器端和客户端代码在 3 个选项之间切换并存储用户的最终答案。

然后我遇到了“单选按钮列表”。这是我的清单。

        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem>Create a new enrollment.</asp:ListItem>
            <asp:ListItem>Change my enrollment information.</asp:ListItem>
            <asp:ListItem>Delete my account information.</asp:ListItem>
        </asp:RadioButtonList>

这要紧凑得多!而不是在复选框选项之间切换。

但是谁能告诉我如何在服务器端接受和存储客户端响应?

在使用复选框之前是这样的:-

if(CheckBox1.Checked){'do something';} 

我不确定如何访问单选按钮列表上的各个项目。谁能帮帮我?

【问题讨论】:

    标签: c# javascript asp.net radiobuttonlist


    【解决方案1】:

    使用RadioButtonList 的SelectedIndex、SelectedItem 和SelectedValue 属性可能是最简单的。

    switch(RadioButtonList1.SelectedValue)
    {
        case "foo":
            // Do your stuff
            break;
    }
    
    // or check it in some if's
    if(RadioButtonList1.SelectedValue == "foo")
    {
        // Do your stuff
    }
    

    【讨论】:

    • 谢谢你:) 正是我想要的。 msdn的属性太多了,好难找。
    猜你喜欢
    • 2018-03-13
    • 2011-09-23
    • 1970-01-01
    • 2011-10-22
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 1970-01-01
    相关资源
    最近更新 更多