A quick example using OnPreRender, if you manually add the items yourself.
THere are several solutions to such a problem, but this is one of them.
THe control in the aspx/ascx file
<asp:dropdownlist id="ddlExample" runat="server" onprerender="ddlExample_OnPreRender"></asp:dropdownlist>
The codebehind for the control/page:
protected void Page_Load(object sender, EventArgs e)
{
if (false == Page.IsPostBack)
{
BindItems(ddlExample);
}
}
const string FoodTemplate = "FoodTemplate";
const string BeverageTemplate = "BeverageTemplate";
private void BindItems(DropDownList ddlControl)
{
if (ddlControl == null)
return;
ddlControl.Items.Clear();
ListItem liFood = new ListItem(FoodTemplate, "0");
ListItem liBeverage = new ListItem(BeverageTemplate, "1");
ddlControl.Items.Add(liFood);
ddlControl.Items.Add(liBeverage);
}
protected void ddlExample_OnPreRender(object sender, EventArgs e)
{
if (sender is DropDownList)
{
DropDownList dl = (DropDownList)sender;
foreach (ListItem listItem in dl.Items)
{
switch (listItem.Text)
{
case FoodTemplate:
listItem.Text = WebApplication11.Properties.Resources.FoodTemplate;
break;
case BeverageTemplate:
listItem.Text = WebApplication11.Properties.Resources.BeverageTemplate;
break;
}
}
}
}