2014-06-18 155 views
0

我使用LINQ獲得一組枚舉除one.This是我的LINQ如何將枚舉綁定到下拉列表?

List<SyncRequestTypeEnum> lstDefaultSyncList = (List<SyncRequestTypeEnum>)(Enum 
    .GetValues(typeof(SyncRequestTypeEnum)) 
    .Cast<SyncRequestTypeEnum>() 
    .Except(new SyncRequestTypeEnum[] { SyncRequestTypeEnum.ProjectLevel })).ToList(); 

SyncRequestTypeEnum是具有3枚舉我的枚舉類。 這裏我使用(Enum.GetValues(typeof(SyncRequestTypeEnum)),所以我正在獲取價值。現在我將這些值綁定到下拉列表中:

((DropDownList)control).DataSource = HtmlEncodeHelper.HtmlEncode(lstDefaultSyncList); 
((DropDownList)control).DataBind(); 

這並不約束實際的枚舉。在UI中,它顯示的值爲System.Data.DataRowView。如果我用GetNames而不是GetValues這是投擲出錯

有人可以幫忙嗎?

+0

更改爲回答下面 –

+0

可能的重複[你如何綁定一個枚舉到一個DropDownList控件在ASP.NET?(http://stackoverflow.com/questions/61953/how-do-you-bind-an -enum-to-a-dropdownlist-control-in-asp-net) – Sean

回答

0

下面的文章SO不正是你所需要的代碼示例

How do you bind an Enum to a DropDownList control in ASP.NET?

你做你之前在搜索貼?

+1

我明白你沒有代表投票結束一個問題,但你可以在旗幟上標記並解釋,而不是張貼副本一個答案。請參閱以下元主題:http://meta.stackoverflow.com/questions/260615/is-a-certain-rep-required-to-be-credited-as-a-close-voter – Sean