Code
1 Public Enum Sexentity
2 {
3Unknown=-1, F=0, M=1
4}
5
6
7 Public Static Datatable getallsex ()
8 {
9 Sexentity sex = New Sexentity ();
10 Datatable dt = New Datatable ();
11 DT. Columns. Add ( " Name " );
12 DT. Columns. Add ( " Value " );
13 Datarow Dr = Null ;
14 System. reflection. fieldinfo [] fields = Sex. GetType (). getfields ();
15 String Strtext = String . Empty;
16 String Strvalue = String . Empty;
17 Foreach (Fieldinfo Field In Fields)
18 {
19 If (Field. fieldtype. isenum = True )
20 {
21 Strvalue = (( Int ) Sex. GetType (). invokemember (field. Name, bindingflags. getfield, Null , Null , Null ). Tostring ();
22 Strtext = Field. Name;
23 Dr = DT. newrow ();
24 Dr [ " Name " ] = Strtext;
25 Dr [ " Value " ] = Strvalue;
26 DT. Rows. Add (DR );
27 }
28 }
29 Return DT;
30 }
1 Dropdownlist1.datasource = Getallsex ();
2 Dropdownlist1.datatextfield = " Name " ;
3 Dropdownlist1.datavaluefield = " Value " ;
4 Dropdownlist1.databind ();