【问题标题】:html is not showing as html in divhtml 未在 div 中显示为 html
【发布时间】:2020-07-28 22:21:52
【问题描述】:

我想在代码中的 div 中设置 HTML,但最终结果如下所示:

这是我的代码:

protected void grdTags_SelectedIndexChanged(object sender, EventArgs e)
{
    string RelatedText = grdTags.SelectedRow.Cells[5].Text;
    dv.InnerHtml = RelatedText;
}

这是 ASPX:

<div id="dv" runat="server">

</div>

【问题讨论】:

标签: c# html asp.net


【解决方案1】:

看起来您正在将文本传递到 HTML。考虑使用 HttpUtility.HtmlEncode()

我没有测试过这个,但是试试:

dv.InnerHtml = HttpUtility.HtmlDecode(grdTags.SelectedRow.Cells[5].Text);

【讨论】:

  • 我现在收到了:<br><h3><span class="AFF_>Affirmed</
  • 我试过 HtmlDecode 并且有效.. 我会更新你的答案
猜你喜欢
  • 2017-05-17
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 2015-05-20
  • 1970-01-01
  • 2014-08-04
  • 1970-01-01
  • 2015-05-04
相关资源
最近更新 更多