473,388 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

insert multiple row form checkboxlist selected value on one click in asp.net C#

am new in C# ASP.NET. I have a problem in CheckBoxList to add selected items in database with multiple rows.

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
  1. foreach (ListItem listitem in cblsubcat.Items)
  2. {
  3.   if (listitem.Selected == true)
  4.   {
  5.     product myproduct;
  6.     myproduct = new product();
  7.     myproduct.ProdName = txtproductname.Text.ToString().Trim();
  8.     GetCategoryId();
  9.     int Subcat_id = int.Parse(cblsubcat.SelectedValue.ToString());
  10.     int Cat_id = int.Parse(cateid.ToString());
  11.     gen_prod_code(Cat_id, Subcat_id);
  12.     myproduct.ProdCode = prodcode;
  13.     myproduct.ProdTitle = txtproductname.Text.ToString().Trim();
  14.     myproduct.CatId = cateid;
  15.     myproduct.SubCatID = int.Parse(cblsubcat.SelectedValue.ToString());
  16.     ProductManager.InsertProductdata(myproduct);
  17.   }
Jan 18 '13 #1
1 5178
Frinavale
9,735 Expert Mod 8TB
At what point in the page life cycle are you doing your DataBind on the CheckBoxList?

If you are doing it in the Page Load event, then you are probably killing all of the selections that the user made....

If this is the case, try moving the call to DataBind into the Page PreRender event. This event occurs after all of the other page events have been performed.

-Frinny
Jan 21 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
24
by: London | last post by:
Hello Can you help me. By ASP How can I get the dropdown(control'name)'s selected value? What is it's property'name?
8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
2
by: Joey | last post by:
Hi There, I am trying to get the selected value of a listbox when I click a button, everything works ok and I can bind the list and when I have a basic page and click a button to invoke a sub it...
12
by: shank | last post by:
I'm trying to use online samples for submitting multiple records from ASP into a stored procedure. Failing! Through the below form, a user could be submitting many records at a time. I'm not...
1
by: Ben | last post by:
I have a formview with a few dropdownlists (software version, database version, etc). When a software version is selected, the database version dropdownlist updates itself accordingly. When in...
2
by: jgosack | last post by:
I have a large database and I would like to control a report by placing Form Feed Commands in a field in the database to control page printing of the report. Is there an easy way to accomplish...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
1
by: polluxsoftech | last post by:
HI, I have 1 listbox named lbCountry i have inserted each selected value from listbox into database by following code: For iLoop = 0 To lbCountry.Items.Count - 1 ' item selected Dim i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.