DotNet Academy of Rajesh Rolen

Solutions by Rajesh Rolen

Fill dropdownlist from enum

as we all know that enum is very useful and sometimes we need to show values of enum on dropdownlist. by following way we can show data of enum in dropdownlist
enum CustomColors
{
BLACK = -1,
RED = 7,
GREEN = 14,
UNKNOWN = -13
}

protected void BtnFillddl_Click(object sender, EventArgs e)
{
EnumToListBox(typeof(DayOfWeek), DropDownList1);

EnumToListBox(typeof(CustomColors), ListBox1);
}
static public void EnumToListBox(Type EnumType, ListControl TheListBox)
{
Array Values = System.Enum.GetValues(EnumType);

foreach (int Value in Values)
{
string Display = Enum.GetName(EnumType, Value);
ListItem Item = new ListItem(Display, Value.ToString());
TheListBox.Items.Add(Item);
}
}

0 comments:

Post a Comment

About this blog

My Blog List

Advertise On This Site

Site Info

Advertise on this Site

To advertise on this site please mail on RajeshRolen@gmail.com

Information Source

About

Pages

Dot Net Academy

Advertis in This Area of Site

Powered by Blogger.

Followers

Search This Blog