/// <summary> /// Build data input control for specified field metadata. /// </summary> /// <param name="fieldMetadata"></param> /// <returns></returns> public override ExtensionDataInputControl BuildDataInputControl(IFieldMetadata fieldMetadata) { EnumerationFieldMetadata metadata = fieldMetadata as EnumerationFieldMetadata; WebControls.PlaceHolder placeHolder = new WebControls.PlaceHolder(); if (metadata.SelectionMode == SelectionModes.Single) { string comboBoxId = string.Format(CultureInfo.InvariantCulture, "SLTFM{0}_{1}", WebUtility.ConvertControlId(metadata.Name), metadata.Ordinal > 0 ? metadata.Ordinal : int.MaxValue); this.ComboBoxFieldValue = new ComboBox { ID = comboBoxId, Editable = false, ForceSelection = true, Mode = ComboBoxDataSourceModes.Local, Width = 154 }; foreach (ExtensionModel.SelectionItem selectionItem in metadata.Items.OrderBy(item => item.Name)) this.ComboBoxFieldValue.Items.Add(new WebControls.ListItem(selectionItem.Name, selectionItem.Value) { Selected = selectionItem.Selected }); placeHolder.Controls.Add(this.ComboBoxFieldValue); if (metadata.IsRequired) { LiteralControl requiredLabel = new LiteralControl("<span class=\"required\">*</span>"); placeHolder.Controls.Add(requiredLabel); } return new ExtensionDataInputControl { Control = placeHolder, OccupiedControlCells = 1 }; } else { string checkBoxGroupId = string.Format(CultureInfo.InvariantCulture, "SLTFM{0}_{1}", WebUtility.ConvertControlId(metadata.Name), metadata.Ordinal > 0 ? metadata.Ordinal : int.MaxValue); this.CheckBoxGroupFieldValue = new CheckBoxGroup { ID = checkBoxGroupId, RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal, RepeatLayout = System.Web.UI.WebControls.RepeatLayout.Flow }; foreach (ExtensionModel.SelectionItem selectionItem in metadata.Items.OrderBy(item => item.Name)) this.CheckBoxGroupFieldValue.Items.Add(new WebControls.ListItem(selectionItem.Name, selectionItem.Value) { Selected = selectionItem.Selected }); placeHolder.Controls.Add(this.CheckBoxGroupFieldValue); if (metadata.IsRequired) { LiteralControl requiredLabel = new LiteralControl("<span class=\"required\">*</span>"); placeHolder.Controls.Add(requiredLabel); } return new ExtensionDataInputControl { Control = placeHolder, OccupiedControlCells = int.MaxValue }; } }
private static CheckBoxGroup CreateCheckBoxGroup(CheckBoxGroupConfiguration controlConfiguration) { CheckBoxGroup checkBoxGroup = new CheckBoxGroup(); foreach (CheckBoxGroupItemConfiguration checkBoxGroupItemConfiguration in controlConfiguration.Items) { ListItem listItem = new ListItem(checkBoxGroupItemConfiguration.Text, checkBoxGroupItemConfiguration.Value) { Selected = checkBoxGroupItemConfiguration.Checked }; checkBoxGroup.Items.Add(listItem); } return checkBoxGroup; }