Conditioning Using Enum Switches

Conditioning can be used by storing lookup values in a database in order to populate a DropDownList control.  This allows the use enums.  On the code side, creating an enum will enable a quick and easy conditioning for identifying values.

What is an Enum?

An enum is a value type with a set of related named constants which is called an enumerator list.  An enum is a primitive datatype meaning it is user defined.

First set your enum values equal to your lookup values.  I assign integer values to the enums which relate to the corresponding lookup value types.

C#
enum DaysOfWeek
{
    None = 0,
    Sunday = 1,
    Monday = 2,
    Tuesday = 3,
    Wednesday = 4,
    Thursday = 5,
    Friday = 6,
    Saturday = 7
}

Use a single method to control all event handlers of a common type, enjoy:

C#
strControlType = ((enmControlType)int.Parse(drTempDataRow["ControlTypeID"].ToString()));
switch (strControlType)
{
	case enmControlType.ListBox:

		..some action..
	break;
}
Scroll to Top