你好 我有以下情况:我有一个WCF网络服务,其中包含枚举。我有另一个应用程序(一个网站),我在其中调用Web服务并使用Web服务中的枚举来创建下拉列表。当我在localhost上运行网站时,一切都很好。但是在我在Web服务器上部署我的解决方案之后,我使用枚举生成的下拉列表被混淆了(枚举的值以另一个顺序显示)。欢迎任何形式的帮助。 查找下面的代码示例: 1.使用的枚举
Hello I have the following situation: I have a WCF web service which contains, among others, enums. I have another application (a web site), in which I call the web service and use the enums from the web service to create dropdown lists. When I run the web site on localhost, everything is fine. But after I deploy my solutions on a web server, my dropdown lists generated with enums are mixed up (the values of the enum are shown in another order). Any kind of help is welcome. Find below a code example: 1. An enum used
[System.Runtime.Serialization.DataContract(Namespace = Cfg.MtplSchemaNamespace)] public enum MtplLegalEntityEnum : int { [System.Runtime.Serialization.EnumMember] PhysicalPerson = 1, [System.Runtime.Serialization.EnumMember] JuridicalPerson = 2, [System.Runtime.Serialization.EnumMember] SelfEmployed = 3 }2.我用来从我的枚举中生成下拉列表的函数:
2. The functions I use to generate dropdown lists from my enums:
public void InitDropDownList(DropDownList dropDownList, Type enumerator) { Hashtable ht = GetEnumForBind(enumerator); dropDownList.DataSource = ht; dropDownList.DataTextField = "value"; dropDownList.DataValueField = "key"; dropDownList.DataBind(); } private Hashtable GetEnumForBind(Type enumeration) { string[] names = Enum.GetNames(enumeration); Array values = Enum.GetValues(enumeration); Hashtable ht = new Hashtable(); for (int i = 0; i < names.Length; i++) { // Get the global resource string. try { // Look in the global resource file called MyResource.resx. string resKey = enumeration.Name + "_" + names[i]; if ((String)GetGlobalResourceObject("enums", resKey) == null) throw new Exception("Could not find global resource."); ht.Add(Convert.ToInt32(values.GetValue(i)).ToString(), (String)GetGlobalResourceObject("enums", resKey)); } catch { ht.Add(Convert.ToInt32(values.GetValue(i)).ToString(), names[i]); } } return ht; }3.函数的调用:
3. The call of the function:
InitDropDownList(ddlPersonType, typeof(Sk.Mtpl.MtplLegalEntityEnum));提前谢谢。
Thank you in advance.
推荐答案请参阅我对该问题的评论。使用枚举类型是高效和健壮的,但是...枚举成员,它们的值和顺序存在一些非平凡的问题。我在文章中描述了这些问题的详细程度: 枚举类型不能枚举!解决.NET和语言限制 [ ^ ]。 即使您在问题中提供的信息远远不够,也许您将能够在阅读了我对枚举问题的解释之后解决了这个问题。 再次,如果你提供更多信息,也许我将能够找出你的问题并建议解决方案。
我发现了问题。该问题由InitDropDownList函数生成。谢谢你的建议Sergey Alexandrovich。 祝你好运, Mihai。 I have found the problem. The issue was generated by the InitDropDownList function. Thank you for your suggestions Sergey Alexandrovich. Best regards, Mihai.
更多推荐
C#Asp.Net Web服务
发布评论