I have one page where I insert Product Information in database on submit button. In the page I'm binding CheckBoxList from database.
My Product code will generate automatically when I check in check box. If I selected 2 check box from checkbox list only one checkbox list value will insert in database. other selected checkbox value or info is not inserted in database.
In my Sql Table I insert Product Name, Product code(that will be generated automatically) product title etc.
So I want multiple rows to be added in database when I selected in CheckBoxList on one Submit click.
My code is
Expand|Select|Wrap|Line Numbers
- foreach (ListItem listitem in cblsubcat.Items)
- {
- if (listitem.Selected == true)
- {
- product myproduct;
- myproduct = new product();
- myproduct.ProdName = txtproductname.Text.ToString().Trim();
- GetCategoryId();
- int Subcat_id = int.Parse(cblsubcat.SelectedValue.ToString());
- int Cat_id = int.Parse(cateid.ToString());
- gen_prod_code(Cat_id, Subcat_id);
- myproduct.ProdCode = prodcode;
- myproduct.ProdTitle = txtproductname.Text.ToString().Trim();
- myproduct.CatId = cateid;
- myproduct.SubCatID = int.Parse(cblsubcat.SelectedValue.ToString());
- ProductManager.InsertProductdata(myproduct);
- }