Read this article in your language IT | EN | DE | ES
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()
ddlFields.Items.Clear()
While BatchEnumerator.MoveNext
Dim ddlItem As New ListItem(BatchEnumerator.Value, BatchEnumerator.Key)
ddlFields.Items.Add(ddlItem)
End While
And that’s it. I’ve found other samples on the web but I’ve combined the best of both worlds here.
f74a051a-40c0-4b8d-a5f1-fb6582baa8f6|0|.0
ASP.NET, Code Snippets, Programming, VB.NET
programming, vb.net, asp.net