3
votes

I have a gridview and i want to insert inside a cell a Panel in which inside i want to render html tags. Instead i see in the text the html tags. 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

4
I think you may want an anchor tag (HyperLink) instead of a LiteralControl. - DOK

4 Answers

4
votes

Modify the Text property of the cell and then it should work. Currently it is just pasting as text.

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

4
votes

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

0
votes

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

0
votes

Use Hyperlink instead of Literal control..