2015-05-14 157 views
0

我有以下enum稱爲BillTypes綁定枚舉AspxListBox

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

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

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

我怎麼能結合這enumAspxListBox

回答

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 
} 

之後,您可以根據變量BillTypesb處理您使用的每個代碼。

+0

這工作。謝謝:) – Musaab

+1

沒問題,那就是'SO'的意思!祝你今天愉快! – cramopy