How to render decoded HTML in a (i.e. a <br>) in GridView cell How to render decoded HTML in a (i.e. a <br>) in GridView cell asp.net asp.net

How to render decoded HTML in a (i.e. a <br>) in GridView cell


What about setting the HtmlEncode property to false? To me, this is much simpler.

<asp:BoundField DataField="MyColumn" HtmlEncode="False" />


Can you subscribe to the RowDataBound event? If you can, you can run:

if (e.Row.RowType == DataControlRowType.DataRow){  string decodedText = HttpUtility.HtmlDecode(e.Row.Cells[0].Text);  e.Row.Cells[0].Text = decodedText;}


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){    for (int i = 0; i < e.Row.Cells.Count; i++)    {        if (e.Row.RowType == DataControlRowType.DataRow)        {            string decodedText = HttpUtility.HtmlDecode(e.Row.Cells[i].Text);            e.Row.Cells[i].Text = decodedText;        }    }}