Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
           }
       }

MIDL
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 = "";
Posted
Updated 11-Aug-10 6:47am
v2

1 solution

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
}


Skip the else clause altogether.

Where I live, people get shot for using goto's.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900