2011-10-24 42 views
3

如果不創建額外的類,我想將一個asp.net DropDown控件綁定到Dictionary<char,string>的集合。可能嗎? 你能提醒一下嗎?以下是我試過的代碼。如何將下拉列表綁定到類型爲Dictionary <char,string>的數據源?

public void FillStatusOptions(Dictionary<char, string> avalibaleStausDictionary) 
{ 
     ddlStatus.DataSource = avalibaleStausDictionary; 

     //TODO: Point to current avalibaleStausDictionary.Key ? 
     ddlStatus.DataValueField = ... ? 

     //TODO: HPoint to current avalibaleStausDictionary.Value ? 
    ddlStatus.DataTextField = ... ? 
} 

回答

2
ddlStatus.DataTextField = "Value"; 
ddlStatus.DataValueField = "Key"; 
1

試試這個:

ddlStatus.DataValueField = "Key"; 
ddlStatus.DataTextField = "Value"; 
1

我總是這樣做的ASPX,而不是後面的代碼:

<asp:DropDownList ID="ddlStatus" runat="server" 
        Value="Key" Text="Value" .. /> 
相關問題