private ListControl GetListControl(BocEnumValueRenderingContext renderingContext) { ListControl listControl = renderingContext.Control.ListControlStyle.Create(false); 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); bool needsNullValueItem = (renderingContext.Control.Value == null) && (renderingContext.Control.ListControlStyle.ControlType != ListControlType.RadioButtonList); if (!renderingContext.Control.IsRequired || needsNullValueItem) { listControl.Items.Add(CreateNullItem(renderingContext)); } IEnumerationValueInfo[] valueInfos = renderingContext.Control.GetEnabledValues(); for (int i = 0; i < valueInfos.Length; i++) { IEnumerationValueInfo valueInfo = valueInfos[i]; ListItem item = new ListItem(valueInfo.DisplayName, valueInfo.Identifier); if (valueInfo.Value.Equals(renderingContext.Control.Value)) { item.Selected = true; } listControl.Items.Add(item); } return(listControl); }
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); }