public void InsertData(Panel panel, int subRequestID) { if (panel.ID != "pnlStoryPic") { //the page is warpped in a pnael, cycle through it to get all the labels on the page foreach (Control control in panel.Controls) { ProjectRequestEntities projectRequest = new ProjectRequestEntities(); Answer answer = new Answer(); answer.subrequestID = subRequestID; //if the current selected control is a panel you need to cycle through this panel to get all the controls in side of it if (control is Panel) { InsertData((Panel)control, subRequestID); } else if (control is TextBox || control is DropDownList || control is RadioButtonList || control is CheckBox) { //check to see what type of control is selected so you can get the appropiate text value if (control is TextBox) { answer.AnswerText = ((TextBox)control).Text; answer.QuestionID = control.ID; } else if (control is DropDownList) { if (((DropDownList)control).SelectedIndex > 0) { answer.AnswerText = ((DropDownList)control).SelectedItem.Text; answer.AnswerValue = ((DropDownList)control).SelectedValue; } else { answer.AnswerText = "No Answer"; } answer.QuestionID = control.ID; } else if (control is RadioButtonList) { if (((RadioButtonList)control).SelectedIndex > -1) { answer.AnswerText = ((RadioButtonList)control).SelectedItem.Text; answer.AnswerValue = ((RadioButtonList)control).SelectedValue; } else { answer.AnswerText = "No Answer"; } answer.QuestionID = control.ID; } else if (control is CheckBox) { if (((CheckBox)control).Checked) { answer.AnswerText = "Yes"; } else { answer.AnswerText = "No"; } answer.QuestionID = control.ID; } else { answer.AnswerText = "No Answer"; answer.QuestionID = control.ID; } projectRequest.AddToAnswers(answer); projectRequest.SaveChanges(); projectRequest.Dispose(); } } } }