private Label GetLabel(BocEnumValueRenderingContext renderingContext) { Label label = new Label { ID = renderingContext.Control.GetValueName(), ClientIDMode = ClientIDMode.Static }; string text; if (renderingContext.Control.IsDesignMode && renderingContext.Control.EnumerationValueInfo == null) { text = c_designModeEmptyLabelContents; // Too long, can't resize in designer to less than the content's width // label.Text = "[ " + this.GetType().Name + " \"" + this.ID + "\" ]"; } else if (renderingContext.Control.EnumerationValueInfo != null) { text = renderingContext.Control.EnumerationValueInfo.DisplayName; label.Attributes.Add("data-value", renderingContext.Control.EnumerationValueInfo.Identifier); } else { text = null; } label.Text = text; label.Width = Unit.Empty; label.Height = Unit.Empty; label.ApplyStyle(renderingContext.Control.CommonStyle); label.ApplyStyle(renderingContext.Control.LabelStyle); return(label); }
private ListControl GetListControl(BocEnumValueRenderingContext renderingContext) { ListControl listControl = renderingContext.Control.ListControlStyle.Create(false); listControl.ClientIDMode = ClientIDMode.Static; listControl.ID = renderingContext.Control.GetValueName(); listControl.Enabled = renderingContext.Control.Enabled; listControl.Width = Unit.Empty; listControl.Height = Unit.Empty; listControl.ApplyStyle(renderingContext.Control.CommonStyle); renderingContext.Control.ListControlStyle.ApplyStyle(listControl); var oneBasedIndex = 1; bool needsNullValueItem = (renderingContext.Control.Value == null) && (renderingContext.Control.ListControlStyle.ControlType != ListControlType.RadioButtonList); if (!renderingContext.Control.IsRequired || needsNullValueItem) { var nullItem = CreateNullItem(renderingContext); if (IsDiagnosticMetadataRenderingEnabled) { nullItem.Attributes[DiagnosticMetadataAttributes.ItemID] = "==null=="; nullItem.Attributes[DiagnosticMetadataAttributes.IndexInCollection] = oneBasedIndex.ToString(); nullItem.Attributes[DiagnosticMetadataAttributes.Content] = HtmlUtility.StripHtmlTags(renderingContext.Control.GetNullItemText()); } listControl.Items.Add(nullItem); oneBasedIndex++; } IEnumerationValueInfo[] valueInfos = renderingContext.Control.GetEnabledValues(); for (int i = 0; i < valueInfos.Length; i++, oneBasedIndex++) { IEnumerationValueInfo valueInfo = valueInfos[i]; ListItem item = new ListItem(valueInfo.DisplayName, valueInfo.Identifier); if (valueInfo.Value.Equals(renderingContext.Control.Value)) { item.Selected = true; } if (IsDiagnosticMetadataRenderingEnabled) { item.Attributes[DiagnosticMetadataAttributes.ItemID] = valueInfo.Identifier; item.Attributes[DiagnosticMetadataAttributes.IndexInCollection] = oneBasedIndex.ToString(); item.Attributes[DiagnosticMetadataAttributes.Content] = HtmlUtility.StripHtmlTags(valueInfo.DisplayName); } listControl.Items.Add(item); } return(listControl); }
/// <summary> /// Renders the concrete <see cref="ListControl"/> control as obtained from <see cref="IBocEnumValue.ListControlStyle"/>, /// wrapped in a <div> /// <seealso cref="ListControlType"/> /// </summary> /// <remarks>The <see cref="ISmartControl.IsRequired"/> attribute determines if a "null item" is inserted. In addition, /// as long as no value has been selected, <see cref="DropDownList"/> and <see cref="ListBox"/> have a "null item" inserted /// even when <see cref="ISmartControl.IsRequired"/> is <see langword="true"/>. /// </remarks> public void Render(BocEnumValueRenderingContext renderingContext) { ArgumentUtility.CheckNotNull("renderingContext", renderingContext); AddAttributesToRender(renderingContext); var tag = renderingContext.Control.ListControlStyle.ControlType == ListControlType.RadioButtonList ? HtmlTextWriterTag.Div : HtmlTextWriterTag.Span; renderingContext.Writer.RenderBeginTag(tag); bool isControlHeightEmpty = renderingContext.Control.Height.IsEmpty && string.IsNullOrEmpty(renderingContext.Control.Style["height"]); bool isControlWidthEmpty = renderingContext.Control.Width.IsEmpty && string.IsNullOrEmpty(renderingContext.Control.Style["width"]); Label label = GetLabel(renderingContext); ListControl listControl = GetListControl(renderingContext); WebControl innerControl = renderingContext.Control.IsReadOnly ? (WebControl)label : listControl; innerControl.Page = renderingContext.Control.Page.WrappedInstance; bool isInnerControlHeightEmpty = innerControl.Height.IsEmpty && string.IsNullOrEmpty(innerControl.Style["height"]); if (!isControlHeightEmpty && isInnerControlHeightEmpty) { renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); } bool isInnerControlWidthEmpty = innerControl.Width.IsEmpty && string.IsNullOrEmpty(innerControl.Style["width"]); if (isInnerControlWidthEmpty) { if (!isControlWidthEmpty) { if (renderingContext.Control.IsReadOnly) { if (!renderingContext.Control.Width.IsEmpty) { renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, renderingContext.Control.Width.ToString()); } else { renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, renderingContext.Control.Style["width"]); } } } } innerControl.RenderControl(renderingContext.Writer); renderingContext.Writer.RenderEndTag(); }
/// <summary> Creates the <see cref="ListItem"/> symbolizing the undefined selection. </summary> /// <returns> A <see cref="ListItem"/>. </returns> private ListItem CreateNullItem(BocEnumValueRenderingContext renderingContext) { ListItem emptyItem = new ListItem(renderingContext.Control.GetNullItemText(), renderingContext.Control.NullIdentifier); if (renderingContext.Control.Value == null) { if (renderingContext.Control.Value == null) { emptyItem.Selected = true; } } return(emptyItem); }