I have a DropDownList shows the company names and a ListBox shows the products of the company I selected in the DropDownList
and I can select many products from ListBox:
in sql I have these tables:
1.company: comp_id,comp_name
2.product: prod_id,prod_name
3.Pro_Comp_details:Pro_Comp_ID,Pro_ID,Comp_ID (bridge table)
In .net I have a page with a button to add to bridge table to add a company and many products to it
this is my code but there is something missing
protected void btn_save_add_Click(object sender, EventArgs e)
{
poc.Pro_Comp_ID = Convert.ToInt32(txt_prod_of_compID_add.Text);
int id1 = Convert.ToInt32(String.Format("select Comp_ID from Company where Comp_Name = '{0}'", ddl_choose_companyName.SelectedValue));
int[] id2 = new int[ListBox1.Items.Count];
foreach (ListItem item in ListBox1.Items)
{
if (item.Selected == true)
{
for (int i = 0; i <= id2.Length; i++)
{
id2[i] = Convert.ToInt32(item);
}
}
}
}