i and having a combo box which contain a valueMember for each item in the combo box.....
i am also having a checklist box which also contain some item ...... what i want to do is to check and uncheck the checklistbox base on the selectedValue of the combobox....
here is my code
- int STAFF_IDs = (int)txtTeacher.SelectedValue;
- con.Open();
- SqlDataAdapter ds1 = new SqlDataAdapter("select * FROM SUBJECT_STAFF where STAFF_ID= '" + STAFF_IDs + "' ", con);
- DataTable dt1 = new DataTable();
- ds1.Fill(dt1);
- if (dt1 != null && dt1.Rows.Count > 0)
- {
- for (int i = 0; i < checkedListBox1.Items.Count; i++)
- {
- for (int k =0; i< dt1.Rows.Count; i++)
- {
- checkedListBox1.SetItemCheckState(i, (STAFF_ID == Convert.ToInt32(dt1.Rows[k]["STAFF_ID"]) ? CheckState.Checked : CheckState.Unchecked));
- } }
- }
the problem i am having is that the checklistbox is not checking the appropriate items in the checklistbox ... again i'm having problem saving all the checked item to the database at once
(NOTE: the purpose of the code is to have a combo box that contain staff name...... and a checklistbox that contain the list of subject..... then i want to assign subjects to staffs from the checklistbox..... again whenever a staff is selected from the combobox, i want the subject that has been assigned to the particular staff be checked on the checklistbox)