views:

119

answers:

1

I am using a asp.net drop down list and it's pulling in a collection of Category Names. The category names have html tags in them like firstname'<'br /'>'lastname. I want to get rid of those tags only in the Drop Down List, I can't change the name. Right now, the break tags show in the drop down.

+11  A: 

You can use String.Replace method in Databoud event

protected void Page_Load(object sender, EventArgs e)
    {
    ddCategories.DataBound += dd_DataBound;
    }

void dd_DataBound(object sender, EventArgs e)
{
    foreach (ListItem listItem in ddCategories.Items)
    {
        listItem.Text = listItem.Text.Replace(@"</br>", string.Empty);
    }
}

or regular expressions for remove all HTML tags:

Regex regex = new Regex("<[^>]+>");
listItem.Text= regex.Replace(listItem.Text, " ");
Jan Remunda