将枚举绑定到AspxListBox

时间:2015-05-14 09:09:44

标签: c# asp.net binding devexpress

我关注了名为python3 -m venv /path/to/new/virtual/environment 的{​​{1}}:

enum

如何将此BillTypes绑定到public enum BillTypes { [EnumProperties("Natural Gas")] NaturalGas= 1, [EnumProperties("Electric")] Electric = 2, [EnumProperties("Water")] Water = 3 }

1 个答案:

答案 0 :(得分:1)

我认为你应该能够运行以下内容:(如果代码不起作用,请耐心等待,因为我不熟悉ASP

BillTypes b = BillTypes.Electric;

AspxListBox alb = new AspxListBox();
alb.Items.Add(BillTypes.Natural_Gas.ToString().Replace("_", " "));
alb.Items.Add(BillTypes.Electric.ToString().Replace("_", " "));
alb.Items.Add(BillTypes.Water.ToString().Replace("_", " "));

alb.SelectedIndexChanged += (ob, ex) => (IndexChanged());

方法IndexChanged

public void IndexChanged()
{
    b = (BillTypes)(alb.SelectedIndex + 1);
    // here you can do whatever you want...
}

请注意稍加编辑的enum课程:

public enum BillTypes
{
    [EnumProperties("Natural Gas")]
    Natural_Gas= 1,

    [EnumProperties("Electric")]
    Electric = 2,

    [EnumProperties("Water")]
    Water = 3
}

在此之后,您可以根据变量BillTypes b处理您使用的每个代码。