Wednesday, December 21, 2011

How to Bind the DropDownList With Enum

0 comments 12/21/2011
Sign up to receive our site updates!
We can Bind DropDownList with no of ways, Now I am going to show how to bind dropdown using ‘enum’. 

Check This How To Bind DropDownList Using List Collection and DataSet in Asp.Net

 Let’s take Countries ‘enum’ as follows

enum enCountries:int{India=0,USA,UK,UAE};

Let see How to Bind the DropDownList With Enum

ddlEnumBind.Items.Add("--Select Country--");

   //get enum items to get the respective enum value
   string[] enumNames=Enum.GetNames(typeof(enCountries));
   foreach (string item in enumNames)
       //get the enum item value
       int value = (int)Enum.Parse(typeof(enCountries), item);
       ListItem listItem = new ListItem(item, value.ToString());
Your Ad Here


Respects for your's Questions & Opinions

  • Friends

    Recent Posts

    Copyright 2008 All Rights Reserved Tech Tasks Template by Rajesh Kumar Chekuri