Skip to content

<xmod:Select>

<xmod:Select> evaluates each child <Case> in order, renders the first one that matches, then stops. If none match and an <Else> is supplied, the <Else> is rendered.

The control is general-purpose — comparisons can be on numbers, dates, text, regex matches, booleans, or DNN role membership. Use it inside an <ItemTemplate> to choose per-record output, or outside any template to choose between blocks of HTML based on URL parameters or user roles.

Example

Show a colored badge based on the FavColor field:

html
<xmod:Template ...>
  <ItemTemplate>
    Your favorite color is:
    <xmod:Select>
      <Case CompareType="Text" Value="[[FavColor]]" Expression="blue">
        <span style="color:#0000FF">BLUE</span>
      </Case>
      <Case CompareType="Text" Value="[[FavColor]]" Expression="red">
        <span style="color:#FF0000">RED</span>
      </Case>
      <Case CompareType="Text" Value="[[FavColor]]" Expression="green">
        <span style="color:#00FF00">GREEN</span>
      </Case>
      <Else>
        We don't know your favorite color
      </Else>
    </xmod:Select>
  </ItemTemplate>
</xmod:Template>

Show a section only to administrators:

html
<xmod:Select>
  <Case CompareType="Role" Expression="Administrators">
    (This area is reserved for Admins)
  </Case>
</xmod:Select>

Properties

PropertyValuesDefaultDescription
ModeStandard InclusiveStandardWhether to render only the first matching <Case> or all matching <Case> tags

Child Tags

TagRequiredDescription
<Case>one or moreA single test. Render its content if the test matches
<Else>optionalRendered if no <Case> matched (or always, in Inclusive mode)

Property Details

  • Mode: How matches are dispatched.

    ValueBehavior
    Standard (default)Walk <Case> tags top-to-bottom. Render the first match and stop. If none match and <Else> is set, render it
    InclusiveRender every <Case> that matches. Always render <Else> if it exists

<Case>

AttributeValuesDefaultDescription
CompareType *Numeric Float Date Text RegEx Boolean RoleDetermines how Value and Expression are compared
Valuestring | tokenLeft-hand side of the comparison. Required for every type except Role
ExpressionstringRight-hand side of the comparison. Required
Operator= <> < > <= >==Comparison operator. Not all operators apply to every CompareType
IgnoreCaseTrue FalseTrueFor Text and RegEx comparisons, whether to ignore case
Culturelocale id | invariant(current culture)Culture used to parse Value and Expression for Numeric, Float, Date, and Text types

* Required attribute

CompareType — what each one means

CompareTypeValue / Expression treated asValid operators
NumericWhole numbersAll six
FloatFloating-point numbersAll six
DateDates / date-timesAll six
TextText stringsAll six (lexicographic)
RegExValue is the subject; Expression is the regex pattern= (matches), <> (does not match)
BooleanBoolean. Numeric 0 is False, anything else is True=, <>
RoleExpression is a comma-delimited list of DNN role names. Value is ignored= (user is in any of the roles), <> (user is not in any)

Role testing as host

When logged in as Host (SuperUser), Role comparisons evaluate to True regardless of the actual role list. Test as a non-host account to see real behavior.

<Else>

<Else> has the same surface as <Case> but ignores CompareType, Value, Expression, and Operator — its content always renders when the <Else> fires.

html
<Else>
  We don't know your favorite color
</Else>

In Standard mode <Else> fires only if no <Case> matched. In Inclusive mode it always fires.