Sometimes we might require to mind dropdowns with some fixed values, in such cases it might not be necessary to bind them with values from database. We can write the values in a enumeration and retrieve the array and bind it with the dropdown. below is an example.

public static class BusinessLogic
{
 public enum SetEnvironment
        {
            Development = 1,
            Testing = 2,
            Staging = 3,
            Production = 4
        };
}

Suppose we have a dropdown named DropDownList1.

So, to populate the dropdown list, the code is as follows:

DropDownList1.DataSource = Enum.GetNames(typeof(BusinessLogic.SetEnvironment));
DropDownList1.DataBind();

Advertisements