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.

1 Answer 1

11

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, " ");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.