/// <summary> /// Renders the drop down list. /// </summary> /// <param name="question">The question.</param> /// <param name="style">The style.</param> /// <param name="defaultOptionText">The text for the default option (signifying no choice).</param> /// <returns> /// A control containing the question and answer choice(s). /// </returns> private static Control RenderDropDownList(IQuestion question, string style, string defaultOptionText) { var ddl = new DropDownList(); if (string.IsNullOrEmpty(style)) { ddl.CssClass = CssClassAnswerVertical; } else { ddl.Attributes.Add("style", style); } ddl.Items.Add(new ListItem(defaultOptionText, string.Empty)); ddl.Attributes.Add("RelationshipKey", question.RelationshipKey.ToString()); ddl.ID = question.RelationshipKey.ToString(); foreach (IAnswer answer in question.GetAnswers()) { var li = new ListItem(answer.Text, answer.Text); li.Attributes.Add("RelationshipKey", answer.RelationshipKey.ToString()); ddl.Items.Add(li); // preselect the answer, if needed if (question.Responses != null) { if (string.Equals(question.FindResponse(answer).AnswerValue, answer.Text)) { li.Selected = true; } } } return(ddl); }
/// <summary> /// Renders the check box list. /// </summary> /// <param name="question">The question.</param> /// <param name="readOnly">if set to <c>true</c> [read only].</param> /// <param name="style">The style.</param> /// <param name="limitReachedErrorFormat">The <see cref="string.Format(System.IFormatProvider,string,object[])"/>-style message for when the maximum number of options has been exceeded</param> /// <returns>A control containing the question and answer choice(s).</returns> private static Control RenderCheckBoxList(IQuestion question, bool readOnly, string style, string limitReachedErrorFormat) { var container = new HtmlGenericControl("SPAN") { ID = "CheckBoxSpan" + question.QuestionId }; if (string.IsNullOrEmpty(style)) { container.Attributes["class"] = CssClassAnswerVertical; } else { container.Attributes.Add("style", style); } if (question.SelectionLimit > 0) { // TODO: Localize limit reached text var limitDiv = new HtmlGenericControl("DIV"); limitDiv.Attributes["class"] = "limit-reached"; limitDiv.InnerText = string.Format(CultureInfo.CurrentCulture, limitReachedErrorFormat, question.SelectionLimit); limitDiv.Style.Add("display", "none"); container.Controls.Add(limitDiv); } foreach (IAnswer answer in question.GetAnswers()) { var cb = new CheckBox(); cb.Attributes.Add("RelationshipKey", answer.RelationshipKey.ToString()); cb.ID = answer.RelationshipKey.ToString(); cb.Enabled = !readOnly; cb.Text = answer.FormattedText; container.Controls.Add(cb); // preselect answer, if needed if (question.Responses != null) { if (string.Equals(question.FindResponse(answer).AnswerValue, bool.TrueString, StringComparison.InvariantCultureIgnoreCase)) { cb.Checked = true; } } if (question.SelectionLimit > 0) { cb.Attributes.Add(HtmlTextWriterAttribute.Onclick.ToString(), "return CheckSelectedCount(this);"); } } return(container); }
/// <summary> /// Renders the vertical option buttons. /// </summary> /// <param name="question">The question.</param> /// <param name="style">The style.</param> /// <returns>A control containing the question and answer choice(s).</returns> private static Control RenderVerticalOptionButtons(IQuestion question, string style) { var rbl = new RadioButtonList { RepeatColumns = 1, RepeatDirection = RepeatDirection.Vertical, RepeatLayout = RepeatLayout.Table, ID = question.RelationshipKey.ToString() }; rbl.Attributes.Add("RelationshipKey", question.RelationshipKey.ToString()); if (string.IsNullOrEmpty(style)) { rbl.CssClass = CssClassAnswerVertical; } else { rbl.Attributes.Add("style", style); } foreach (IAnswer answer in question.GetAnswers()) { //// 1 to skip the blank entry var li = new ListItem(answer.Text, answer.Text); li.Attributes.Add("RelationshipKey", answer.RelationshipKey.ToString()); rbl.Items.Add(li); // preselect answer, if needed if (question.Responses != null) { if (string.Equals(answer.Text, question.FindResponse(answer).AnswerValue, StringComparison.InvariantCultureIgnoreCase)) { li.Selected = true; } } } return(rbl); }
/// <summary> /// Renders the vertical option buttons. /// </summary> /// <param name="question">The question.</param> /// <param name="style">The style.</param> /// <returns>A control containing the question and answer choice(s).</returns> private static Control RenderVerticalOptionButtons(IQuestion question, string style) { var rbl = new RadioButtonList { RepeatColumns = 1, RepeatDirection = RepeatDirection.Vertical, RepeatLayout = RepeatLayout.Table, ID = question.RelationshipKey.ToString() }; rbl.Attributes.Add("RelationshipKey", question.RelationshipKey.ToString()); if (string.IsNullOrEmpty(style)) { rbl.CssClass = CssClassAnswerVertical; } else { rbl.Attributes.Add("style", style); } foreach (IAnswer answer in question.GetAnswers()) { //// 1 to skip the blank entry var li = new ListItem(answer.Text, answer.Text); li.Attributes.Add("RelationshipKey", answer.RelationshipKey.ToString()); rbl.Items.Add(li); // preselect answer, if needed if (question.Responses != null) { if (string.Equals(answer.Text, question.FindResponse(answer).AnswerValue, StringComparison.InvariantCultureIgnoreCase)) { li.Selected = true; } } } return rbl; }
/// <summary> /// Renders the drop down list. /// </summary> /// <param name="question">The question.</param> /// <param name="style">The style.</param> /// <param name="defaultOptionText">The text for the default option (signifying no choice).</param> /// <returns> /// A control containing the question and answer choice(s). /// </returns> private static Control RenderDropDownList(IQuestion question, string style, string defaultOptionText) { var ddl = new DropDownList(); if (string.IsNullOrEmpty(style)) { ddl.CssClass = CssClassAnswerVertical; } else { ddl.Attributes.Add("style", style); } ddl.Items.Add(new ListItem(defaultOptionText, string.Empty)); ddl.Attributes.Add("RelationshipKey", question.RelationshipKey.ToString()); ddl.ID = question.RelationshipKey.ToString(); foreach (IAnswer answer in question.GetAnswers()) { var li = new ListItem(answer.Text, answer.Text); li.Attributes.Add("RelationshipKey", answer.RelationshipKey.ToString()); ddl.Items.Add(li); // preselect the answer, if needed if (question.Responses != null) { if (string.Equals(question.FindResponse(answer).AnswerValue, answer.Text)) { li.Selected = true; } } } return ddl; }
/// <summary> /// Renders the check box list. /// </summary> /// <param name="question">The question.</param> /// <param name="readOnly">if set to <c>true</c> [read only].</param> /// <param name="style">The style.</param> /// <param name="limitReachedErrorFormat">The <see cref="string.Format(System.IFormatProvider,string,object[])"/>-style message for when the maximum number of options has been exceeded</param> /// <returns>A control containing the question and answer choice(s).</returns> private static Control RenderCheckBoxList(IQuestion question, bool readOnly, string style, string limitReachedErrorFormat) { var container = new HtmlGenericControl("SPAN") { ID = "CheckBoxSpan" + question.QuestionId }; if (string.IsNullOrEmpty(style)) { container.Attributes["class"] = CssClassAnswerVertical; } else { container.Attributes.Add("style", style); } if (question.SelectionLimit > 0) { // TODO: Localize limit reached text var limitDiv = new HtmlGenericControl("DIV"); limitDiv.Attributes["class"] = "limit-reached"; limitDiv.InnerText = string.Format(CultureInfo.CurrentCulture, limitReachedErrorFormat, question.SelectionLimit); limitDiv.Style.Add("display", "none"); container.Controls.Add(limitDiv); } foreach (IAnswer answer in question.GetAnswers()) { var cb = new CheckBox(); cb.Attributes.Add("RelationshipKey", answer.RelationshipKey.ToString()); cb.ID = answer.RelationshipKey.ToString(); cb.Enabled = !readOnly; cb.Text = answer.FormattedText; container.Controls.Add(cb); // preselect answer, if needed if (question.Responses != null) { if (string.Equals(question.FindResponse(answer).AnswerValue, bool.TrueString, StringComparison.InvariantCultureIgnoreCase)) { cb.Checked = true; } } if (question.SelectionLimit > 0) { cb.Attributes.Add(HtmlTextWriterAttribute.Onclick.ToString(), "return CheckSelectedCount(this);"); } } return container; }