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
user1292656
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
Rachel Gallen
source
to share
set the HtmlEncode property to false in the associated GridViews field that contains HTML
+4
Stoy
source
to share
I think you can use HttpUtility.HtmlDecode in System.Net nameSpace. I have not tested it, but you can try it.
0
İsmail Aydın
source
to share
Use Hyperlink, not Literal control.
0
Tamal kanti dey
source
to share