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);
}
}
+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 to share