Skip to content

Bind and render a drop-down list

Support enum-sourced binding and a read-only rendering mode for the drop-down. Host page calls DataBind, or the ASP.NET page lifecycle invokes Render.

Field Value
Operation ID OP-V2-005
Trigger Host page calls DataBind, or the ASP.NET page lifecycle invokes Render.
Inputs EnumDatasource, MapUnderscore, ReadOnly, ValueText, control width/style.
Outputs Populated list items on bind; interactive drop-down or read-only textbox markup on render.
Primary components SAIFDropDownList
Entry point SAIF.Presentation.Web.Controls.V2/SAIFDropDownList.vb

Steps

  1. On DataBind, if EnumDatasource is set, read the enum member names via System.Enum.GetNames. (BR-V2-027)
  2. If MapUnderscore is true, replace _ with a space in every name before assigning them as the base DataSource. (BR-V2-028)
  3. Call the base DataBind. (BR-V2-029)
  4. On Render, when ReadOnly is true, create a read-only TextBox with CSS class disabledbackcolor, width reduced by 5 pixels when the control width is 5 or greater, and text taken from the selected item — or from ValueText when the selected value is blank. (BR-V2-030, BR-V2-031, BR-V2-032, BR-V2-033)
  5. When not read-only and Visible, call the base Render. (BR-V2-034, BR-V2-035)
  6. On failure: clear the selection and re-render once.
  7. SelectedItemAsEnum converts between selected item text and enum value, reversing the underscore mapping. (BR-V2-036)

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([DataBind]) --> E{EnumDatasource set?}
    E -->|Yes| Names[GetNames + optional underscore mapping]
    Names --> Base[MyBase.DataBind]
    E -->|No| Base
    Base --> RenderStart([Render]) 
    RenderStart --> RO{ReadOnly?}
    RO -->|Yes| Text[Substitute read-only TextBox]
    RO -->|No| Vis{Visible?}
    Vis -->|Yes| BR[MyBase.Render]
    BR -->|Throws| Retry[Clear selection, retry once]
    Vis -->|No| NoOut([No output])

Failure and edge-case behavior

  • On failure: clear the selection and re-render once.

Sources

  • SAIF.Presentation.Web.Controls.V2/SAIFDropDownList.vb