2010-03-28 70 views

回答

0

最接近的將是一個整數屬性。

0

枚舉是編譯時常量。如果數據庫值在運行時不會改變,那麼您始終可以使用codegen工具從數據庫生成枚舉值(在預編譯時)。如果他們會改變,你可能需要做一個字符串屬性或類似的東西,而不是Enum。

0

你必須寫一個自定義的TypeConverter來完成這個任務。

public class MyItemsConverter : TypeConverter 
{ 

    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 
    { 
     StringCollection values = new StringCollection(); 

     // Connect to database and read values. 

     return new StandardValuesCollection(values); 
    } 

    public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 
    { 
     return (context != null); 
    } 

    public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 
    { 
     return true; 
    } 

} 

public class MyControl : WebControl 
{ 

    [TypeConverter(typeof(MyItemsConverter))] 
    public string MyItem { get; set; } 

} 
+0

hi.thnx的答覆!代碼工作,但是當從下拉列表中選擇GetStandardValues值獲取與每個調用兩次點擊... whts去錯了? – anay 2010-03-29 15:19:35

+0

@anay,你說得對。儘管它只是在設計時發生,但並不重要。無論如何,你可以緩存數據來提高性能。 http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/4769c7b5-fd66-4490-8fa0-e1cecad80bce – 2010-03-29 19:32:08