如何从RadioButtonList获取选定的值? [英] How to get the selected value from RadioButtonList?

查看:99
本文介绍了如何从RadioButtonList获取选定的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个通过数据绑定填充的RadioButtonList

I have a RadioButtonList on my page that is populated via Data Binding

<asp:RadioButtonList ID="rb" runat="server">
</asp:RadioButtonList>
<asp:Button Text="Submit" OnClick="submit" runat="server" />

如何获取用户在提交"方法中选择的单选按钮的值?

How do I get the value of the radio button that the user selected in my "submit" method?

推荐答案

ASPX代码如下所示:

The ASPX code will look something like this:

 <asp:RadioButtonList ID="rblist1" runat="server">

    <asp:ListItem Text ="Item1" Value="1" />
    <asp:ListItem Text ="Item2" Value="2" />
    <asp:ListItem Text ="Item3" Value="3" />
    <asp:ListItem Text ="Item4" Value="4" />

    </asp:RadioButtonList>

    <asp:Button ID="btn1" runat="server" OnClick="Button1_Click" Text="select value" />

以及背后的代码:

protected void Button1_Click(object sender, EventArgs e)
        {
            string selectedValue = rblist1.SelectedValue;
            Response.Write(selectedValue);
        }

这篇关于如何从RadioButtonList获取选定的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆