日期:2014-05-20  浏览次数:20853 次

登陆按钮的验证不起作用
做Windows窗体设计时写的登陆窗体,这段代码是写在登陆按钮上,
用户名和密码的验证有用,就登陆类型没用,不输入类型也可以直接登陆,
这是怎么回事啊?
那位高手帮忙一下,谢谢拉...

 private void btnlogin_Click(object sender, EventArgs e)
  {
   
   
  if (txtuName.Text.Trim() == "")
  {
  MessageBox.Show("请输入用户名", "登陆提示",
  MessageBoxButtons.OK, MessageBoxIcon.Information);
  txtuName.Focus();
  return;
  }
  if (txtpwd.Text.Trim() == "")
  {
  MessageBox.Show("请输入密码", "登陆提示",
  MessageBoxButtons.OK, MessageBoxIcon.Information);
  txtpwd.Focus();
  return;
  }
  if (cboType.Text.Trim() == "")
  {
  MessageBox.Show("请选择登陆类型", "登陆提示",
  MessageBoxButtons.OK, MessageBoxIcon.Information);
  cboType.Focus();
  return ;
  }
   
   
  AdminForm bb = new AdminForm();
  bb.Show();
   
  }


------解决方案--------------------
if (cboType.Text.Trim() == "") 

//这里cboType.Text 有値吧。。。
MessageBox.Show("请选择登陆类型", "登陆提示", 
MessageBoxButtons.OK, MessageBoxIcon.Information); 
cboType.Focus(); 
return ; 


------解决方案--------------------
if (cboType.Text.Trim() == "") 

你下断点看下,这里是什么值

可以用下面判断
if(cboType.SelectedIndex==-1)
{}
------解决方案--------------------
if(cboType.SelectedValue==null)

return ; 

使用String.IsNullOrEmpty判断