这是代码:
if (roomGender == "M")
{
if (gender == "F")
{
row.Cells[5].BackColor = Color.FromName("#FF0000");
args.IsValid = false;
vldGender.ErrorMessage = building +" " + room + ": You cannot place a female in this space";
}
else
{
vldGender.ErrorMessage = "";
}
}
//end male gender check
//Female gender check
if (roomGender == "F")
{
if (gender == "M")
{
row.Cells[5].BackColor = Color.FromName("#FF0000");
args.IsValid = false;
vldGender.ErrorMessage = building +" " + room + ": You cannot place a male in this space";
}
else
{
vldGender.ErrorMessage = "";
}
}
//end female gender check
//Validate Names
string last = ((TextBox)row.FindControl("txtLast")).Text;
string first = ((TextBox)row.FindControl("txtFirst")).Text;
if (last == "" && first != "")
{
row.Cells[3].BackColor = Color.FromName("#FF0000");
args.IsValid = false;
vldLast.ErrorMessage = building +" " + room + ": The last name cannot be blank";
}
else
{
vldLast.ErrorMessage = "";
}
if (last != "" && first == "")
{
row.Cells[4].BackColor = Color.FromName("#FF0000");
args.IsValid = false;
vldFirst.ErrorMessage = building +" " + room + ": The first name cannot be blank";
}
else
{
vldFirst.ErrorMessage = "";
}
if (last != "" && first != "" && gender == "")
{
row.Cells[5].BackColor = Color.FromName("#FF0000");
args.IsValid = false;
vldGender2.ErrorMessage = building +" " + room + ": A gender must be selected";
}
else
{
vldGender2.ErrorMessage = "";
}
if (!(regLast.IsValid))
{
row.Cells[3].BackColor = Color.FromName("#FF0000");
regLast.ErrorMessage = building +" " + room + ": The last name is incorrect, please check the name";
}
if (!(regFirst.IsValid))
{
row.Cells[4].BackColor = Color.FromName("#FF0000");
regFirst.ErrorMessage = building +" " + room + ": The first name is incorrect, please check the name";
}
}
}
}
我的问题 因为这是在 if 语句之一无法验证时使用 if 语句,所以 if 语句停止在该行上。因此,该行的其余字段未经过验证。
我有字段名,姓氏和性别。
如果我忘记添加名字和姓氏,但没有添加性别。
此验证只会显示我缺少名字,直到名字被固定后才会检查姓氏。
他们有什么方法可以解决这个问题,以便同时检查两个字段吗?