W
WebBuilder451
i'm trying to modify some code to accept an enum then use reflection to fill
a dropdown list. If i name the type directly, replace enm with the real name
of the enum it works, no suprise. Question is can i make this dynamic. I
throws an error on run that it can't find the namespace. I understand why,
but is what i'm trying to do possible?
public static void BindEnumToDropDown(ref DropDownList ddl, Enum enm)
{
FieldInfo[] myEnumFields = typeof(enm).GetFields(); // ERRORS HERE
foreach (FieldInfo myField in myEnumFields)
{
if (!myField.IsSpecialName && myField.Name.ToLower() !=
"notset")
{
int myValue = (int)myField.GetValue(0);
ddl.Items.Add(new ListItem(myField.Name,
myValue.ToString()));
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
a dropdown list. If i name the type directly, replace enm with the real name
of the enum it works, no suprise. Question is can i make this dynamic. I
throws an error on run that it can't find the namespace. I understand why,
but is what i'm trying to do possible?
public static void BindEnumToDropDown(ref DropDownList ddl, Enum enm)
{
FieldInfo[] myEnumFields = typeof(enm).GetFields(); // ERRORS HERE
foreach (FieldInfo myField in myEnumFields)
{
if (!myField.IsSpecialName && myField.Name.ToLower() !=
"notset")
{
int myValue = (int)myField.GetValue(0);
ddl.Items.Add(new ListItem(myField.Name,
myValue.ToString()));
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes