protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BLL objquestionlist = new BLL(); DataTable dtquestion = objquestionlist.GetQuizQuestionList(Convert.ToInt32(Request.QueryString["QuizID"].ToString())); Session["QuizQuestionList"] = dtquestion; Session["CurrentQuestionIndex"] = "0"; if (dtquestion != null && dtquestion.Rows.Count > 0) { DataTable dtQuestionDetails = objquestionlist.GetQuestionDetails(Convert.ToInt32(dtquestion.Rows[0][0].ToString())); if (dtQuestionDetails != null && dtQuestionDetails.Rows.Count > 0) { qNo.InnerText = "1"; qtitle.InnerText = dtQuestionDetails.Rows[0]["Question_Title"].ToString(); QDesc.InnerText = dtQuestionDetails.Rows[0]["Question_Desc"].ToString(); DataTable dtoption = objquestionlist.GetOptionDetails(Convert.ToInt32(dtQuestionDetails.Rows[0]["Question_Id"].ToString())); if (dtQuestionDetails.Rows[0]["Question_Type"].ToString() == "MCQ") { MCQ.DataSource = dtoption; MCQ.DataTextField = "Question_Option"; MCQ.DataValueField = "Question_Option"; MCQ.DataBind(); } else if (dtQuestionDetails.Rows[0]["Question_Type"].ToString() == "TF") { TF.DataSource = dtoption; TF.DataTextField = "Question_Option"; TF.DataValueField = "Question_Option"; TF.DataBind(); } else { SCQ.DataSource = dtoption; SCQ.DataTextField = "Question_Option"; SCQ.DataValueField = "Question_Option"; SCQ.DataBind(); } } } } }
protected void PopulateQuestionDetails(int CurrentQuestionIndex) { BLL objquestionlist = new BLL(); DataTable dtquestion = (DataTable)Session["QuizQuestionList"]; DataTable dtAnswer; Session["CurrentQuestionIndex"] = CurrentQuestionIndex; if (dtquestion != null && dtquestion.Rows.Count > 0) { DataTable dtQuestionDetails = objquestionlist.GetQuestionDetails(Convert.ToInt32(dtquestion.Rows[CurrentQuestionIndex][0].ToString())); if (dtQuestionDetails != null && dtQuestionDetails.Rows.Count > 0) { qNo.InnerText = Convert.ToString(CurrentQuestionIndex + 1); qtitle.InnerText = dtQuestionDetails.Rows[0]["Question_Title"].ToString(); QDesc.InnerText = dtQuestionDetails.Rows[0]["Question_Desc"].ToString(); DataTable dtoption = objquestionlist.GetOptionDetails(Convert.ToInt32(dtQuestionDetails.Rows[0]["Question_Id"].ToString())); if (Session["dtAnswer"] != null) { dtAnswer = (DataTable)Session["dtAnswer"]; DataTable AnsExsit = dtAnswer.AsEnumerable().Where(o => o.Field <string>("QID") == dtQuestionDetails.Rows[0]["Question_Id"].ToString()).AsDataView().ToTable(); if (AnsExsit != null && AnsExsit.Rows.Count > 0) { if (dtQuestionDetails.Rows[0]["Question_Type"].ToString() == "MCQ") { string[] MCQAns = AnsExsit.Rows[0]["AnsOption"].ToString().Split(','); MCQ.Visible = true; MCQ.DataSource = dtoption; MCQ.DataTextField = "Question_Option"; MCQ.DataValueField = "Question_Option"; MCQ.DataBind(); for (int i = 0; i < MCQ.Items.Count; i++) { foreach (string ans in MCQAns) { if (ans != "") { if (i == Convert.ToInt32(ans) - 1) { MCQ.Items[i].Selected = true; // MCQAns = MCQAns + "," + Convert.ToString(i + 1); } } } } TF.Visible = false; SCQ.Visible = false; } else if (dtQuestionDetails.Rows[0]["Question_Type"].ToString() == "TF") { TF.Visible = true; TF.DataSource = dtoption; TF.DataTextField = "Question_Option"; TF.DataValueField = "Question_Option"; TF.DataBind(); // TF.SelectedItem.Text = AnsExsit.Rows[0]["AnsOption"].ToString(); TF.Items.FindByText(AnsExsit.Rows[0]["AnsOption"].ToString().Trim()).Selected = true; MCQ.Visible = false; SCQ.Visible = false; } else { SCQ.Visible = true; SCQ.DataSource = dtoption; SCQ.DataTextField = "Question_Option"; SCQ.DataValueField = "Question_Option"; SCQ.DataBind(); SCQ.SelectedIndex = Convert.ToInt32(AnsExsit.Rows[0]["AnsOption"].ToString()) - 1; MCQ.Visible = false; TF.Visible = false; } } else { if (dtQuestionDetails.Rows[0]["Question_Type"].ToString() == "MCQ") { MCQ.Visible = true; MCQ.DataSource = dtoption; MCQ.DataTextField = "Question_Option"; MCQ.DataValueField = "Question_Option"; MCQ.DataBind(); TF.Visible = false; SCQ.Visible = false; } else if (dtQuestionDetails.Rows[0]["Question_Type"].ToString() == "TF") { TF.Visible = true; TF.DataSource = dtoption; TF.DataTextField = "Question_Option"; TF.DataValueField = "Question_Option"; TF.DataBind(); MCQ.Visible = false; SCQ.Visible = false; } else { SCQ.Visible = true; SCQ.DataSource = dtoption; SCQ.DataTextField = "Question_Option"; SCQ.DataValueField = "Question_Option"; SCQ.DataBind(); MCQ.Visible = false; TF.Visible = false; } } } else { if (dtQuestionDetails.Rows[0]["Question_Type"].ToString() == "MCQ") { MCQ.Visible = true; MCQ.DataSource = dtoption; MCQ.DataTextField = "Question_Option"; MCQ.DataValueField = "Question_Option"; MCQ.DataBind(); TF.Visible = false; SCQ.Visible = false; } else if (dtQuestionDetails.Rows[0]["Question_Type"].ToString() == "TF") { TF.Visible = true; TF.DataSource = dtoption; TF.DataTextField = "Question_Option"; TF.DataValueField = "Question_Option"; TF.DataBind(); MCQ.Visible = false; SCQ.Visible = false; } else { SCQ.Visible = true; SCQ.DataSource = dtoption; SCQ.DataTextField = "Question_Option"; SCQ.DataValueField = "Question_Option"; SCQ.DataBind(); MCQ.Visible = false; TF.Visible = false; } } } } }