Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a check box list, and I want to insert its Checked items to Database;
I used this code:
C#
for (int i = 0; i < checkBox_service.Items.Count; i++)
        {
            
            if (checkBox_service.Items[i].Selected == true)
            {
                strcheck += "" + checkBox_service.Items[i].ToString() + ",";
            }
        }

In Database it is displaying
C#
System.Web.UI.WebControls.CheckBoxList

in CheckBox field instead of Selected item. All other fields are having correct data as per entered...
I couldn't find any error, please guide me...
Posted
Updated 28-Jan-16 19:27pm
v2
Comments
DamithSL 29-Jan-16 2:16am    
how you bind data to checkBox_service? can you update the question with that code?
Member 12133159 29-Jan-16 2:33am    
I have manually Entered the Values... Using Add Items
DamithSL 29-Jan-16 2:45am    
you haven't show us how you insert data to database

Try using either the Text or Value property of CheckBoxListItem (whatever suits you). Like this:

C#
checkBox_service.Items[i].Text 
checkBox_service.Items[i].Value
 
Share this answer
 
Comments
Member 12133159 29-Jan-16 2:03am    
Not Working any other suggestion
dan!sh 29-Jan-16 2:08am    
What do you mean by not working?
Member 12133159 29-Jan-16 2:40am    
It is not taking the Text or Value property in this code line...
dan!sh 29-Jan-16 2:42am    
What do you mean by not taking? Have you debugged this particular line on code in the loop?
Member 12133159 29-Jan-16 2:49am    
Means same output 'System.Web.UI.WebControls.CheckBoxList'.....
In databse
try with checkBox_service.Items[i].Text
 
Share this answer
 
Comments
Member 12133159 29-Jan-16 2:03am    
Not Working any other suggestion

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