AnantLabs / codesmith

Automatically exported from code.google.com/p/codesmith
1 stars 0 forks source link

Create DataSource Control so we can easily bind WebForm UI Controls to Generated Enums. #507

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I know that this is outside of the scope of PLINQO... However, it would be nice 
if we had a DataSource Control that wrapped our generated enums so they could 
be binded to controls declaratively.

Currently you need to use a collection and populate like this:

var names = Enum.GetNames(typeof(MyEnum));
var values = Enum.GetValues(typeof(MyEnum));

var list = new SortedDictionary<int, string>();
for (int index = 0; index < names.Length; index++)
{
    list.Add((int)((MyEnum)values.GetValue(index)), names[index]);
}

DropDownList.DataTextField = "Value";
DropDownList.DataValueField = "Key";
DropDownList.DataSource = list;
DropDownList.DataBind();

Original issue reported on code.google.com by bniemyjski on 30 Sep 2010 at 2:27