Reputation: 2560
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);
}
}
Upvotes: 3
Views: 17492
Reputation: 75
set the HtmlEncode property to false in the GridViews bound field that contains the HTML
Upvotes: 4
Reputation: 35
I think, you can use HttpUtility.HtmlDecode in System.Net nameSpace. I did not test it but it you can try it.
Upvotes: 0
Reputation: 28563
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
Upvotes: 4