Created
February 1, 2012 12:13
-
-
Save findel/1716775 to your computer and use it in GitHub Desktop.
Looping through enumerator to bind to DropDownList
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // My enumerator | |
| public enum MyKind | |
| { | |
| None = 0, | |
| MyFirstValue = 1, | |
| MySecondValue = 2, | |
| MyThirdValue = 3 | |
| } | |
| // My extention methods for the enumerator | |
| public static class MyKindExtensions | |
| { | |
| public static string GetName(this MyKind source) | |
| { | |
| string name = ""; | |
| switch(source) | |
| { | |
| case MyKind.MyFirstValue: | |
| name = "The First Value"; | |
| break; | |
| case MyKind.MySecondValue: | |
| name = "The Second Value"; | |
| break; | |
| case MyKind.MyThirdValue: | |
| name = "The Third Value"; | |
| break; | |
| case MyKind.None: | |
| default: | |
| name = "Value not available"; | |
| break; | |
| } | |
| return name; | |
| } | |
| public static string GetValueString(this MyKind source) | |
| { | |
| return ((int)source).ToString(CultureInfo.InvariantCulture); | |
| } | |
| } | |
| // Code to use in the *.aspx.cs file | |
| // Drop down for lead times. | |
| foreach(MyKind kind in Enum.GetValues(typeof(MyKind))) | |
| { | |
| DropDownBla.Items.Add(new ListItem(kind.GetName(), kind.GetValueString())); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment