private HtmlGenericControl CreateIndiciaQuestion(SurveyAttribute attr) { HtmlGenericControl div = new HtmlGenericControl(); div.ID = "Indicia_" + attr.Id.ToString() + "_div"; div.Attributes["class"] = "IndiciaQuestionWrap"; div.TagName = "div"; Label lbl = new Label(); lbl.ID = "Indicia_" + attr.Id.ToString() + "_lbl"; lbl.Attributes["class"] = "IndiciaQuestionLabel"; lbl.Text = attr.Caption; div.Controls.Add(lbl); IIndiciaAttributes IndiciaCtrl = null; switch (attr.DataType) { //TODO: add in more complex controls, validators and default values. Out of scope for this initial investigation case "D": //D=Date = Calendar control IndiciaCtrl = new IndiciaCalendar(); break; case "L": //L=List => DropDownList IndiciaCtrl = CreateDropDownList(attr); break; case "T": //T=Text => Textbox IndiciaCtrl = CreateTextBox(attr); break; default: HtmlGenericControl html = new HtmlGenericControl(); html.TagName = "p"; html.Attributes.Add("class", "IndiciaError"); html.InnerHtml = "Error: Unknown Indicia type"; div.Controls.Add(html); break; } if (IndiciaCtrl != null) { IndiciaCtrl.IndiciaAttributeType = attr.AttributeType; IndiciaCtrl.IndiciaAttributeID = attr.Id; IndiciaCtrl.IndiciaIsRequired = attr.IsRequired; IndiciaCtrl.IndiciaAttributeCaption = attr.Caption; IndiciaCtrl.IndiciaAttributeJSONID = attr.IndiciaJSONAttributeName; WebControl ctrl = (WebControl)IndiciaCtrl; ctrl.ID = "Indicia_" + attr.Id.ToString(); ctrl.CssClass = "IndiciaQuestion"; div.Controls.Add(ctrl); } return div; }
private IndiciaTextBox CreateTextBox(SurveyAttribute attr) { Indicia.WebControls.IndiciaTextBox tbx = new Indicia.WebControls.IndiciaTextBox(); if (!(String.IsNullOrEmpty(attr.DefaultTextValue))) { tbx.Text = attr.DefaultTextValue; } return tbx; }
private IndiciaDropDownList CreateDropDownList(SurveyAttribute attr) { Indicia.WebControls.IndiciaDropDownList ddl = new Indicia.WebControls.IndiciaDropDownList(); DataService ds2 = new DataService(); ds2.RequestData.Add("termlist_id", attr.TermlistId.ToString()); List<TermItem> ddlData = ds2.GetTermList(); ddl.DataSource = ddlData; ddl.DataTextField = "Term"; ddl.DataValueField = "TermId"; ddl.DataBind(); return ddl; }