如何从RadioButtonList获取所选择的值?

时间:2022-12-03 10:23:48

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

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

<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?

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

4 个解决方案

#1


40  

The ASPX code will look something like this:

ASPX代码如下所示:

 <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" />

And the code behind:

和背后的代码:

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

#2


12  

Using your radio button's ID, try rb.SelectedValue.

使用你的单选按钮的ID,试试rb.SelectedValue。

#3


-1  

string radioListValue = RadioButtonList.Text;

#4


-4  

radiobuttonlist.selected <value> to process with your code.

radiobuttonlist。选择要使用代码处理的

#1


40  

The ASPX code will look something like this:

ASPX代码如下所示:

 <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" />

And the code behind:

和背后的代码:

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

#2


12  

Using your radio button's ID, try rb.SelectedValue.

使用你的单选按钮的ID,试试rb.SelectedValue。

#3


-1  

string radioListValue = RadioButtonList.Text;

#4


-4  

radiobuttonlist.selected <value> to process with your code.

radiobuttonlist。选择要使用代码处理的