C# RadioButton

来源:百度知道 编辑:UC知道 时间:2024/05/02 18:59:02
C#中的单选按钮
我拖了两个RadioButton在设计中
一个text=男 一个text=女
就是要实现性别选择;
后面一个按钮把选择的结果显示到 Label1 中
我在按钮的click事件中用:
if(radioButton1.Checked == true)
label1.text ="性别男";
else if(radioButton2.Checked == true)
label1.text ="性别女";
else label1.text =="还没有选择!";

根本对我没反应 好像并没有判断按钮的选中情况
还是我判断的不对啊
别人说要RadioButton 成组 然后在ITEM里设置
我怎么找不到这个
谢谢!!

狂晕!这么写不对!
if(radioButton1.Checked)
label1.text ="性别男";
else if(radioButton2.Checked)
label1.text ="性别女";
else label1.text ="还没有选择!";

aspx中:

<asp:RadioButton ID="RadioButton1" AutoPostBack="true" GroupName="g" runat="server" OnCheckedChanged="RadioButton1_CheckedChanged" />
<asp:RadioButton ID="RadioButton2" AutoPostBack="true" GroupName="g" runat="server" OnCheckedChanged="RadioButton2_CheckedChanged" /></div>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

cs中:
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
this.TextBox2.Text = "nv";
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
this.T