如何在 C# 中对 ResourceSet 进行排序 [英] How to sort ResourceSet in C#

查看:29
本文介绍了如何在 C# 中对 ResourceSet 进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 filetypes.resx 的资源文件.我如何想出将资源值绑定到下拉列表的一些方法,但我不知道如何对 ResourceSet 的值进行排序.

这是我目前所做的,

文件类型.resx

  • 名称、值
  • A,1

  • B,2

  • C,3

绑定下拉列表的代码

<代码>DropDownList1.DataSource = Resources.FileTypes.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);DropDownList1.DataTextField = "Key";DropDownList1.DataValueField = "值";DropDownList1.DataBind();

结果

<前>一种C乙

如您所见,结果未排序.请帮我解决这个问题.

非常感谢:)

解决方案

ressource set 有一个 IDictionaryEnumerator 所以我猜它的 item 是 DictionaryEntry 类型的,试着像这样对数据源进行排序:

DropDownList1.DataSource = Resources.FileTypes.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true).OfType().OrderBy(i => i.Value);

嗯,我没有打开 Visual Studio,所以如果它不能立即工作,请不要怪我:)

I have a resource file named filetypes.resx. Some how I figured out to bind the resource values to dropdownlist, but I don't know how to sort the values of ResourceSet.

Here is what I did so far,

FileTypes.resx

  • Name,Value
  • A,1

  • B,2

  • C,3

code to bind dropdownlist


DropDownList1.DataSource = Resources.FileTypes.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
DropDownList1.DataTextField = "Key";
DropDownList1.DataValueField = "Value";
DropDownList1.DataBind();

Result

 A
 C
 B

As you can see the result is not sorted. Please help me to solve this issue.

Many thanks in advance :)

解决方案

The ressource set has a IDictionaryEnumerator so I guess that its items are of type DictionaryEntry, try to sort the data source like this :

DropDownList1.DataSource = Resources.FileTypes.ResourceManager
    .GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true)
    .OfType<DictionaryEntry>()
    .OrderBy(i => i.Value);

Hum, I have no visual studio opened so don't blame me in case it does not work immediatly :)

这篇关于如何在 C# 中对 ResourceSet 进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆