protected void Page_Load(object sender, EventArgs e) { QuestionProxy question = GetNextQuestion(); if (question != null) { QuestionLabel.Text = question.Text; switch (question.Type) { case "text": TextBox textBox = new TextBox(); textBox.ID = "AnswerTxtBox"; PlaceHolder1.Controls.Add(textBox); break; case "radio": RadioButtonList radioButtonList = new RadioButtonList(); GetQuestionOptions(question.Id).ForEach(x => radioButtonList.Items.Add(new ListItem(x.Text))); PlaceHolder1.Controls.Add(radioButtonList); break; case "checkbox": CheckBoxList checkBox = new CheckBoxList(); List <QuestionOptionProxy> opts = GetQuestionOptions(question.Id); opts.ForEach(x => checkBox.Items.Add(new ListItem(x.Text))); checkBox.DataSource = opts; PlaceHolder1.Controls.Add(checkBox); break; } } }
/// <summary> /// Formats the question. /// </summary> /// <param name="q">The q.</param> /// <returns>System.String.</returns> private string FormatQuestion(QuestionProxy q) { switch (q.qtype) { case 0: //numeric { if (double.IsNegativeInfinity(q.minval) && double.IsPositiveInfinity(q.maxval)) return string.Empty; else if (double.IsNegativeInfinity(q.minval)) //no lower bound return string.Format("[<= {0}]", q.maxval.ToString("0.00")); else if (double.IsPositiveInfinity(q.maxval)) //no lower bound return string.Format("[>= {0}]", q.minval.ToString("0.00")); else return string.Format("[{0} -> {1}]", q.minval.ToString("0.00"), q.maxval.ToString("0.00")); } case 1: //categorical { StringBuilder sb = new StringBuilder(); sb.Append("["); foreach (var c in q.categories) { sb.Append(c); if(c != q.categories.Last()) sb.Append(" / "); } sb.Append("]"); return sb.ToString(); } default: //textual return string.Empty; } }