Dynamically resolve a resource key

asp.net, c#, localization

Solution

You could do this in Code-Behind on the ItemDataBound Event.

Label lv = (Label)e.Item.FindControl("lbl");


ResourceManager resMngr = new ResourceManager(typeof(SupertextCommon.Default));
lv.Text = resMngr.GetObject(someProperty, culture);

Problem

I would like to insert a string (key) into a `'<%$ Resources:resFile, someKey %>'` statement dynamically at runtime. Right now I have this: ``` <asp:Label runat="server" id="lbl" Text='<%$ Resources:resFile, someKey %>'/> ``` which is useless to me, because the key "someKey" is static and will always converge to the same x translations. I've tried doing things like this: ``` <asp:Label runat="server" id="lbl" Text='<%$ Resources:resFile, '<%#Eval("someProperty")%>' %>'/> ``` But this doesn't quite compile. I'm not sure if you can have nested `<%%>` statements, so thats why i'm asking here. I've also tried a variety of things with `GetGlobalResourceObject()` but that doesn't do what i want either. The thing is that i am binding a list to a repeater, and one of the items in the datasource will contain the key that will match a key in the resource files. If anyone knows a way how to achieve this, be it with nested `<%%>` statements or be it any other way, i'd be happy to try it out.

Original source