user1292656
user1292656

Reputation: 2560

Render HTML tags in GridView Cell

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

Upvotes: 3

Views: 17492

Answers (4)

Stoy
Stoy

Reputation: 75

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

Upvotes: 4

Tamal Kanti Dey
Tamal Kanti Dey

Reputation: 576

Use Hyperlink instead of Literal control..

Upvotes: 0

İsmail Aydın
İsmail Aydın

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

Rachel Gallen
Rachel Gallen

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

Related Questions