我想你應該可以運行以下命令:(請多多包涵,如果代碼不工作,由於我不是所熟悉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
處理您使用的每個代碼。
這工作。謝謝:) – Musaab
沒問題,那就是'SO'的意思!祝你今天愉快! – cramopy