I have several DropDownLists on a form which are dynamically populated as they move down the form pulling data from a DB. The data is all HTMLEncoded so I need to HTMLDecode the data to display the text.
I created a method to do this and trigger it ‘ondatabound’ for each DDL
ondatabound="SortHTMLModel"
BUT whats annoying I have the same method just changing the DDL name on each one. I want a generic single method each DDL could call. Here is the one for the DDL called ddlfuel
protected void SortHTML(object sender, EventArgs e)
{
foreach (ListItem item in ddlFuel.Items)
{
item.Text = Server.HtmlDecode(item.Text);
}
}
And one for the DDL called ddlModel
protected void SortHTMLModel(object sender, EventArgs e)
{
foreach (ListItem item in ddlModel.Items)
{
item.Text = Server.HtmlDecode(item.Text);
}
}
You see my predicament! So annoying I just can’t figure out the syntax for one method
IIRC, the sender of an event is the actual control, so you could also say
and bind each DropDownList’s DataBound event to SortHTML