Convert enumerator to datatable for binding purposes

serkan sendur

by using the code below you can bind your enums to your dropdown lists


Serkan Şendur

1,586 Views
About the Author
public static DataTable ConvertEnumToDataTable(Enum parEnumToConvert)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID");
            dt.Columns.Add("Name");
            int i = 0;
            foreach (string s in Enum.GetNames(typeof(yourCustomEnum)))
            {
                DataRow dr = dt.NewRow();
                dr["ID"] = i;
                dr["Name"] = s;
                dt.Rows.Add(dr);
                i++;
            }
            return dt;
            
        }