Monthly Archives: February 2010

Populate Dropdown Using Enum (Asp.Net MVC)

Hi folks, I am new to Asp.Net MVC. I was trying to populate a dropdown from an Enum.

After searching on web couldn’t realy find a direct solution, so thought to do in my own way and finally  got this solution.

Now here is an excertp from my code.

MyEmun is the Enum from which I want to populate the dropdown.

public enum MyEnum


Day = 1 ,

Month = 2,

Year = 3


MyEnumList() is a function that return a collection of SelectListItem that is used to populate the Dropdown.

private IList<SelectListItem> MyEnumList()


string[] names = Enum.GetNames(typeof(MyEnum));

Array values = Enum.GetValues(typeof(MyEnum));

IList<SelectListItem> items = new List<SelectListItem>();

for (int i = 0; i < names.Length; i++)


int val = (int)values.GetValue(i);

items.Add(new SelectListItem


Text = names[i],

Value = val.ToString()



return items;


Pass the return value of MyEnumList()  using ViewData from your controller to the view where you have the dropdown

ViewData[“MyList”] = MyEnumList ();

And finally populate your dropdown

<%=Html.DropDownList(“MyDropDown”,new SelectList((IList)ViewData[“MyList “],”Value”,”Text”))%>

hope this would helps 🙂

Incredible Illusion! Try It

Nothing in life is simple as it seems!
This has GOT to be one of the Best illusion ever created. Incredible!

If you watch the above images from your seat in front of the computer, Mr. Angry is on the left, and Mrs.Calm is on the right.

Get up from your seat, and move back 12 feet, and PRESTO!! they switch places!!

It is said this illusion was created by

Phillippe G.Schyns and Aude Oliva of the Univ. of Glasgow .

This proves that we may not be seeing what’s actually there, all the time!!