Q:

Localization + Databinding in markup

I have a asp:DropDownList populated by a SqlDataSource.
The Text displayed by each item on the DropDownList is in one of the columns returned by the SqlDataSource. 
In the aspx page:
DataTextField="IceCreamFlavour"

This works. What I want to do though is use the IceCreamFlavour values as a key to resource files (.resx) which would match the key to the appropriate text (as determined by the Culture)
How do I do that databinding + localization in markup?
I tried this for example, and it doesn't work: (the name 'Localization' does not exist in the current context)
DataTextField='<%# Resources:Localization, Eval("IceCreamFlavour") %>'

A:

Ok, so this is not possible purely through markup. I did the following:
in markup:
<asp:DropDownList ID="flavourDDList" runat="server"
  DataSourceID="flavourDataSource" DataValueField="flavourID" DataTextField="flavourText"
  OnDataBound="SetLocalizedText"
</asp:DropDownList>

in code-behind:
protected void SetLocalizedText(Object sender, EventArgs e)
{
  foreach (ListItem item in ((DropDownList)sender).Items)
  {
    object localizedText = HttpContext.GetGlobalResourceObject("Localization", item.Text);
    if (localizedText != null)
      item.Text = localizedText.ToString();
  }
}

So the database contains the text in (for example) english, and the localized text is applied right after databinding the control.

