Rendering HTML Tags in a GridView Cell

I have a gridview and I want to insert inside a cell a panel, inside which I want to display html tags. Instead, I see html tags in the text. Any ideas?

   protected void grdThreat_RowDataBound(object sender, GridViewRowEventArgs e)
{

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Panel mainPanel = new Panel(); 
        mainPanel.Controls.Add(new LiteralControl(e.Row.Cells[4].Text)); 
            e.Row.Cells[4].Controls.Add(mainPanel);
    }
}

      

enter image description here

+3


source to share


4 answers


Change the Text property of the cell and then it should work. It is currently just pasted as text.



also see How to render decoded HTML in (like a <br>) in a GridView cell

+4


source


set the HtmlEncode property to false in the associated GridViews field that contains HTML



+4


source


I think you can use HttpUtility.HtmlDecode in System.Net nameSpace. I have not tested it, but you can try it.

0


source


Use Hyperlink, not Literal control.

0


source







All Articles