Click here to Skip to main content
16,017,922 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a dynamic check-box list Which value comes from database table (named T_Hygene). now i want to save some selected value to another table named (T_Transaction)in the database.how can i do this?
Posted
Comments
syed shanu 22-Dec-14 1:44am    
So what is the problem
Dew Drops 22-Dec-14 1:57am    
how can i save the multiple value of checkboxlist in database?
Anisuzzaman Sumon 22-Dec-14 2:24am    
Show Some Code And then ask specifically

Suppose CBLList is your checkboxlist, so you have to first get all the values of checkboxs which are checked & have to be save in table in database.Below is the code which will give you comma separated values of all the checked checkboxes in the string variable chkbox_selected.

string chkbox_selected;
for (int i = 0; i < CBLList.Items.Count; i++)
{
if (CBLList.Items[i].Selected == true)
{
chkbox_selected += CBLList.Items[i].Value + ",";
}
}
chkbox_selected = chkbox_selected.Remove(chkbox_selected.Length - 1, 1);

Now in chkbox_selected you have all the checked value of checkbox in comma separated mode. Now you can use these accordingly.

Thanks
 
Share this answer
 
HTML
string sno = "";
int y = 0;
for (int i = 0; i < chk.Items.Count; i++)
{
    if (chk.Items[i].Selected)
    {
        if (y == 0)
        {
            sno = chk.Items[i].Value;
        }
        else
        {
            sno += "," + chk.Items[i].Value;
        }
        y++;
    }
}
 
Share this answer
 
Try like this,
C#
string lst = "";
foreach (ListItem lists in Your_DynamicCheckBoxID.Items)
{
lst = lists.ToString() + "," + lst;
string StringAdd= lst.ToString();
int comma = StringAdd.LastIndexOf(',');
string FinalString= StringAdd.Substring(0, comma);   
}

This FinalString Returns all selected text from your dynamic check box list.You can store this string value to your Table (T_Transaction) by using insert query.
If you want to store each selected value seperately,just omit StringAdd, FinalString and just pass string lst value to your database.
 
Share this answer
 
v2
you should be knowing the name of multiple checkboxes and they should be fixed.

So you can store in an order which you can identify with a flag(0 & 1).

eg. ColumnName wiill have checkBox1(UnChecked),checkBox2(checked),checkBox3(checked),checkBox4(UnChecked) & checkBox5(checked) values

so values can be stored liked 01101
 
Share this answer
 
Comments
Paras Raibagkar 6-Oct-15 13:00pm    
I am using GridView and I have added Check Box to the GridView through Template
I want to do the following:
1) I want to store the checked(ticked) box's value (taking it as 1) into a database table column
2)Store the unchecked (unticked) box's value (taking it as 0) into another column of same database table

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