如何在 GridView 单元格中的(即 <br>)中呈现解码的 HTML [英] How to render decoded HTML in a (i.e. a <br>) in GridView cell

查看:11
本文介绍了如何在 GridView 单元格中的(即 <br>)中呈现解码的 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 GridView 绑定到 LINQ 查询.LINQ语句创建的对象中的一些字段是字符串,需要换行.

I'm binding a GridView to an LINQ query. Some of the fields in the objects created by the LINQ statement are strings, and need to contain new lines.

显然,GridView HTML 对每个单元格中的所有内容进行编码,因此我无法插入 <br/>在单元格内创建一个新行.

Apparently, GridView HTML-encodes everything in each cell, so I can't insert a <br /> to create a new line within a cell.

如何告诉 GridView 不要对单元格的内容进行 HTML 编码?

How do I tell GridView not to HTML encode the contents of cells?

也许我应该使用不同的控件?

Maybe I should use a different control instead?

推荐答案

你能订阅 RowDataBound 事件吗?如果可以,你可以运行:

Can you subscribe to the RowDataBound event? If you can, you can run:

if (e.Row.RowType == DataControlRowType.DataRow)
{
  string decodedText = HttpUtility.HtmlDecode(e.Row.Cells[0].Text);
  e.Row.Cells[0].Text = decodedText;
}

这篇关于如何在 GridView 单元格中的(即 &lt;br&gt;)中呈现解码的 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆