Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

How to store the multiple selection of check boxes in the database.
Then retrieve the values and diplay it in the check boxes

Help please

Thanks and Advance.

Regards,
Praveena
Posted
Comments
Aniket Yadav 7-Feb-12 4:21am    
Are This Check boxes in the grid?
And How Do you want to save it in DB? In Y/N format Or True/False format?
Will you please elaborate a little?
praveena.karthi 7-Feb-12 4:35am    
Yes the CheckBoxes are in grid.
I need to store the numberic values.

I can store the values into the database using comma(,).
Now I need to separate the comma and display the selected items.

My Insert code is


protected void Submitbtn_Click(object sender, EventArgs e)
{


List<string> staffNRICs = new List<string>();
string i = string.Empty;
foreach (GridViewRow gvr in StaffGridView.Rows)
{
CheckBox currentCheckBox = (CheckBox)gvr.FindControl("CheckBox1");

if (currentCheckBox.Checked == true)
{

Label currentLabel = (Label)gvr.FindControl("Label1");

staffNRICs.Add(currentLabel.Text);
i += currentLabel.Text + ",";
}
}
string sqlStatement
= " insert into S5 values (' " + i + " ' )";


DBHandler dbHandler = new DBHandler(sqlStatement);
dbHandler.NonQuery();
}

Its working fine.
I need the help to retrieve and display the values to the check box

thanks

Regards,
Praveena

In one unsigned integer word. Each check box should correspond to one individual bit. I hope you know how to do bitwise arithmetic (binary OR, AND, ('|', '&'), '<<', '>>', etc.).

—SA
 
Share this answer
 
v2
You are saving the data into list.

And the data in list is somewhat like this i guess,
1 + 0 + 0 + 1 + and so on..


Now let's consider that chkbox1 = 1, chkbox2 = 1, chkbox3 = 0, chkbox4 = 0, chkbox5 = 1, so the data is like,

1 + 1 + 0 + 0 + 1


Now here you have to split the list as shown below

VB
String Data1 = ""
Data1 = Split(List1.List(i), "+")


Here '+' is your separator

Now check if Data1 is 1 Then chkbox1.checked = true else false.

Hope This will help you
 
Share this answer
 

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