如何获得单选按钮的价值? [英] How to get value of Radio Buttons?
本文介绍了如何获得单选按钮的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含单选按钮的组框例如.
I have a group box contains radio buttons eg.
o 男性
o 女性
我希望我的代码获取单选按钮的选定值并将其复制到字符串类型变量请使用简单的代码,因为它不是很专业
i want my code to get the selected value of radio button and copy it to string type variable kindly use simple code cause m not very professional
谢谢
推荐答案
对于Win Forms:
要从单选按钮中获取值(假设您想要的是值,而不是文本),请获取Checked属性:
To get the value (assuming that you want the value, not the text) out of a radio button, you get the Checked property:
string value = "";
bool isChecked = radioButton1.Checked;
if(isChecked )
value=radioButton1.Text;
else
value=radioButton2.Text;
对于Web表单:
<asp:RadioButtonList ID="rdoPriceRange" runat="server" RepeatLayout="Flow">
<asp:ListItem Value="Male">Male</asp:ListItem>
<asp:ListItem Value="Female">Female</asp:ListItem>
</asp:RadioButtonList>
然后在某些按钮中单击CS
And CS-in some button click
string value=rdoPriceRange.SelectedItem.Value.ToString();
这篇关于如何获得单选按钮的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文