简体   繁体   English

在GridView Cell中渲染HTML标记

[英]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. 我有一个gridview,我想在一个单元格内插入一个Panel,其中我想要渲染html标签。 Instead i see in the text the html tags. 相反,我在文本中看到了html标签。 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);
    }
}

在此输入图像描述

Modify the Text property of the cell and then it should work. 修改单元格的Text属性,然后它应该工作。 Currently it is just pasting as text. 目前它只是粘贴为文本。

also see How to render decoded HTML in a (ie a <br>) in GridView cell 另请参阅如何在GridView单元格中的(即<br> <br>)中呈现已解码的HTML

在包含HTML的GridViews绑定字段中将HtmlEncode属性设置为false

I think, you can use HttpUtility.HtmlDecode in System.Net nameSpace. 我想,您可以在System.Net nameSpace中使用HttpUtility.HtmlDecode。 I did not test it but it you can try it. 我没有测试它,但你可以尝试一下。

使用超链接而不是Literal控件..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM