Populate an ASP.net ListBox with the values of an enumeration

|
Kind of like: Obtaining the string value of an enumeration name (but not).

        public void PopulateListBoxFromEnum(DropDownList listBox, Type enumeration)
        {
            string[] descriptiveValues = Enum.GetNames(enumeration);
            foreach (string descriptiveValue in descriptiveValues)
            {
                int statusValue = Convert.ToInt32(Enum.Parse(enumeration, descriptiveValue, true));
                listBox.Items.Add(new ListItem(descriptiveValue, statusValue.ToString()));
            }
        }

Not a lot more to say really, other than, see above ;-)

About this Entry

This page contains a single entry by Robert Wray published on February 11, 2009 8:30 AM.

Licensing a Build Server was the previous entry in this blog.

Exclude SCC / VSSSCC files from Web Setup Projects is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 5.04