I had desire to populate a DropDownList with values from a resource file. Using the resource name as the ddl value and the resource value as ddl text. There’s other reasons I need to do this but I’m simplifying it here.
The resource file name is: “BatchFields_ADMRACClaim”
The DropDownList is called “ddlFeilds”
So first I get the resource file object and then I do a GetType() to initialize it. If anyone has any other suggestions for this, please let me know. Without the GetType() line or pulling out a value first, the GetResourceSet later is Nothing.
Dim BatchFileResource As ResourceManager
BatchFileResource = Resources.BatchFields_ADMRACClaim.ResourceManager()
Dim Value As String = BatchFileResource.GetType.Assembly.FullName
Then once I have the resource file in the “BatchFileResource” object, I can then loop through the items and dump them into a DropDownList.
Dim BatchResourceSet As ResourceSet = BatchFileResource.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, True, False)
Dim BatchEnumerator As IDictionaryEnumerator = BatchResourceSet.GetEnumerator()
Dim ddlItem As New ListItem(BatchEnumerator.Value, BatchEnumerator.Key)
And that’s it. I’ve found other samples on the web but I’ve combined the best of both worlds here.