Click here to Skip to main content
16,004,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

am working on asp.net project using c# and Sqlserver 2005.

I want to Insert checkboxes values into database field.

I have 5 checkboxes on my webpage.

Checkbox1
Checkbox2
Checkbox3
Checkbox4
Checkbox5

If checkbox1 is selected the value in table column should be 1
If checkbox2 is selected the value in table column should be 1
If checkbox3 selected the value in table column should be 1
If checkbox4 is NOT selected the value in table column should be 0
If checkbox5 is NOT selected the value in table column should be 0

In column it should save as 11100


Please can u help me.
Thanks.
Posted
Updated 17-Nov-14 21:38pm
v2
Comments
CHill60 18-Nov-14 2:49am    
What problem are you having? Convert your pseudo code into real code and give it a try. It's your homework...you won't learn anything unless you try!
Member239258 18-Nov-14 3:13am    
Please help me.

Just I want to insert checkbox checked value into column as 11100

Thanks.

for windows Application

C#
string chkVal = checkBox1.CheckState.GetHashCode().ToString()+
                            checkBox2.CheckState.GetHashCode().ToString()+
                            checkBox3.CheckState.GetHashCode().ToString()+
                            checkBox4.CheckState.GetHashCode().ToString()+
                            checkBox5.CheckState.GetHashCode().ToString();


for web Application

C#
string chkVal = (CheckBox1.Checked ? "1" : "0").ToString() +
                        (CheckBox2.Checked ? "1" : "0").ToString() +
                        (CheckBox3.Checked ? "1" : "0").ToString() +
                        (CheckBox4.Checked ? "1" : "0").ToString() +
                        (CheckBox5.Checked ? "1" : "0").ToString();
        Label1.Text = chkVal;

:):):)
 
Share this answer
 
v2
Comments
Member239258 18-Nov-14 5:04am    
kumar sir, it inserts all zeros as 00000

I need checked values to be 1 and unchecked must be 0

Please help.
Thanks
Shambhoo kumar 18-Nov-14 5:16am    
Then what you want to inset in database.
Member239258 18-Nov-14 5:21am    
Sir, Please help.

I have 5 checkboxes checkboxes1 to checkboxes 5
When i check checkbox1 in column it should be 1....if not selected it should be 0

For example:
10000
here, 1 is checked and others not checked.

Please help.
Thanks.
Shambhoo kumar 18-Nov-14 5:26am    
dear my code already done this task so use "for web application" code.
Member239258 18-Nov-14 5:36am    
No sir, it inserts all zeros for me.
Take a StringBuilder.
Append 1 or 0 to it after checking the CheckBox Checked status.
C#
StringBuilder sb = new StringBuilder();

if(checkbox1.Checked)
    sb.Append("1");
if(checkbox2.Checked)
    sb.Append("1");
........

Then at last just save sb.ToString() to Database.
 
Share this answer
 
v2

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