for循环中的问题 [英] Problem in for loop
问题描述
我遇到了问题,即,如果我从下拉列表中选择一个项目并按下按钮,它将进入grid2;如果我再次选择同一项目并按下按钮,则不会进入网格2显示标签项目已存在".现在,我从下拉列表中选择另一个项目,然后按一下按钮,再次允许它.现在,如果从grid2中已经存在的下拉列表中选择一个项目,那么最终它也将进入Grid2,这是不允许的.
I am having problem, i,e., if I choose an item from the dropdownlist and press the button, it enters into grid2 and if I again choose the same item and press the button, it does not enter into grid 2 showing a label "Item already exists" . Now that I choose a different item from the drop down list and press the button it is again allowed. Now if a select an item from the dropdown already present in the grid2 then ultimately it enters into Grid2 too which should not be allowed.
for (int i = 0; i < GridView2.Rows.Count; i++)
{
if (GridView2.Rows[i].Cells[11].Text==concat)
{
Label22.Visible = true;
goto No;
}
else
{
break;
}
}
Label22.Visible = false;
helper.InsertPlannedMaterialMasterRequest2(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox6.Text, DropDownList2.SelectedValue, DropDownList3.SelectedValue, Convert.ToInt32(TextBox11.Text), DropDownList5.SelectedValue, Convert.ToInt32(DropDownList4.SelectedValue), Convert.ToInt32(TextBox13.Text), DropDownList6.SelectedValue,department, DateTime.Now,concat);
LoadMasterRequests();
LoadDetailRequests();
LoadItems();
BindData();
BindData2();
BindData3();
goto d;
No:
Label22.Visible = true;
d:
TextBox6.Text = "";
TextBox7.Text = "";
TextBox11.Text = "";
TextBox13.Text = "";
推荐答案
如果第一项不是所选的,则跳出循环
If the first item is not the selected one, you break out of the loop
if (GridView2.Rows[i].Cells[11].Text==concat)
{
Label22.Visible = true;
goto No;
}
else
{
break; // Problem here
}
完全跳过else子句.
在我住的地方,人们会因为使用goto
而被枪杀.
Skip the else clause altogether.
Where I live, people get shot for using goto
''s.
这篇关于for循环中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!