I'm trying to pass an Enum into a method that will create columns for a gridview. I can pass the Enum as Enum passEnum OR Type enumType, and either works, just not together. What I mean is if I pass it as a type the Enum.GetNames() method accepts it, and if I pass it as an enum, the StringEnum.GetString() method accepts it. But I can't pass one and have them both accept it and I can't pass them separately (enum and type) and have both accept it. The method that AMOST works:
public static void AddColumnsToGridView(GridView gv, Enum passEnum, Type enumType)
{
BoundField bf = new BoundField();
int c = 0;
foreach (string item in Enum.GetNames(enumType))
{
bf = new BoundField();
bf.HeaderText = StringEnum.GetString((passEnum)c);
bf.DataField = item;
bf.ItemStyle.CssClass = "siteFont leftPaddingThree";
bf.SortExpression = item;
gv.Columns.Add(bf);
c++;
}
}
I get a red squiggle line under passEnum that says: "The type or namespace 'passEnum' cannot be found... etc". For some reason I can get this to work outside of a method like this:
BoundField bf = new BoundField();
int c = 0;
foreach (string item in Enum.GetNames(typeof(PatientRX)))
{
bf = new BoundField();
bf.HeaderText = StringEnum.GetString((PatientRX)c);
bf.DataField = item;
bf.ItemStyle.CssClass = "siteFont leftPaddingThree";
bf.SortExpression = item;
gvRX.Columns.Add(bf);
c++;
}
The StringEnum.GetString() method gets a string value attached to the enum. It requires an enum to be passed to it. How can I get this to work in a method?