我使用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
這是投擲出錯
有人可以幫忙嗎?
更改爲回答下面 –
可能的重複[你如何綁定一個枚舉到一個DropDownList控件在ASP.NET?(http://stackoverflow.com/questions/61953/how-do-you-bind-an -enum-to-a-dropdownlist-control-in-asp-net) – Sean