首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

radiobutton使用,该如何处理

2012-01-26 
radiobutton使用我用radiobutton做性别,然后想将被选中的性别提交到数据库,但是注册表中没有性别的数据,请

radiobutton使用
我用radiobutton做性别,然后想将被选中的性别提交到数据库,但是注册表中没有性别的数据,请帮我指点指点!
 public string radioText;
......................
strSql = "insert into 注册表(用户名,密码,确认密码,公司名称,公司税号,负责人,性别,固定电话,手机号码,Email,传真,详细地址) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + radioText + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox11.Text + "','" + TextBox12.Text + "')";

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
  {
  if (RadioButton1.Checked)
  {
  radioText = "男";
  }
  else
  {
  radioText = "女";
  }

[解决办法]
if (RadioButton1.Checked) 

radioText = "男"; 

else 

radioText = "女"; 


这段代码应该写在两个Radiobutton事件当中
[解决办法]
你可以把 

 if (RadioButton1.Checked) 

radioText = "男"; 

else 

radioText = "女"; 


放到Button 事件当中 不要写到RadioButton1事件中

 string sex;
//获取性别
if (RadioButton1.Checked)
{
sex = "男";
}
else
{
sex= "女";
}

热点排行