views:

357

answers:

4

Hi All,

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 :)

+1  A: 

ResourceSet has a property named Table, of type HashTable. Maybe you could generate a sorted list out of that table (manually, or by using LINQ), then assign this list to DropDownList1.DataSource.

Konamiman
thank you, let me try
Sandy
A: 

Hashtable is not a sorted collection.

adatapost
+2  A: 

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 :)

Manitra Andriamitondra
Thank you... that's perfect :)
Sandy
A: 

Hashtable tbl = Resources.FileTypes.ResourceManager.
GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true).Table;
List source = new List(tbl.Values);
source.Sort();
DropDownList1.DataSource = source;
DropDownList1.DataBind();

Tror