protected void Button1_Click(object sender, EventArgs e) { CheckBoxList3.Focus(); CheckBoxList2.Items.Clear(); CheckBoxList3.Items.Clear(); // show Question Button for (int i = 0; i < CheckBoxList1.Items.Count; i++) { if (CheckBoxList1.Items[i].Selected == true) { // fetch question with dropdwn condition SqlCommand Ques_cmd = new SqlCommand(); Ques_cmd.CommandText = "SELECT Question_Id, Question_Details FROM question_bank WHERE Subject_Id =" + DropDownList2.SelectedValue + " AND Chapter_Id =" + CheckBoxList1.Items[i].Value + " AND Minimum_Marks=" + DropDownList3.SelectedValue; Ques_cmd.Connection = cn; SqlDataReader dr = Ques_cmd.ExecuteReader(); // here we assign checkbox2 to question and checkbox3 assign id of question while (dr.Read()) { CheckBoxList2.Items.Add(Convert.ToString(dr.GetValue(1))); CheckBoxList3.Items.Add(Convert.ToString(dr.GetValue(0))); } dr.Close(); } } CheckBoxList2.Focus(); }