Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ii want to store multiple selected checkbox in database...so m using below code:-
C#
string selectedItems = string.Empty;
        foreach (ListItem item in this.CheckBox1.Items)
        {
            if (item.Selected)
                selectedItems += item + ",";
        }
        SqlCommand cmd = new SqlCommand("Insert into Candidates(Candidate_Pref_Job_Cat) values('" + selectedItems + "')", cn);
        cn.Open(); // I am assuming that you have written down the connection string.
        int iCount = cmd.ExecuteNonQuery();
        cn.Close();


bt error is:- does not contain a definition for 'CheckBox1' and no extension method 'CheckBox1' accepting a first argument of type could be found....

m using single checkbox nd use Repeater Control to display multiple checkbox....so how to declare checkbox in my code??????or what is error in code????
Posted
Updated 13-Jun-12 21:18pm
v2

Try to use CheckBoxList control instead of just a checkbox+repeater. This is the control designed exactly for such purposes.

Refer: MSDN: CheckBoxList Web Server Control Declarative Syntax[^]
MSDN: CheckBoxList Class[^]

Alternatively, have a look at this control too: Multiselect Dropdown for Web Applications[^]
 
Share this answer
 
Get the reapeter control and do the loop for each row.From each row,use FindControl("Checkbox1") and type casting it to check box object then check whether the check box is selected or not.Based on that get the value of checked items.
 
Share this answer
 
firstly you take check box(id=chkAdminList) list in place of check box
then use it
for (int i = 0; i < chkAdminList.Items.Count; i++)
{

if (chkAdminList.Items[i].Selected)
{

//send check box value in the database
}
else
{
}
}
 
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