简体   繁体   English

ASP.NET Webforms的中继器中Eval数据库列值的HTML解码

[英]HTML Decoding of Eval database column value in repeater of ASP.NET webforms

I am trying to get HTML encoded value(processed and input by responsive Text Editor control) from database and decode it to display as normal plain text in the webform page. 我试图从数据库中获取HTML编码的值(通过响应的文本编辑器控件进行处理和输入),并将其解码以在Webform页面中显示为普通纯文本。

I am able to get the values with Eval method in the repeater like below 我可以使用中继器中的Eval方法获取值,如下所示

<p><%#Eval("Content")%></p>

It works perfectly fine. 它工作得很好。 I further tried to shorten it with following code 我进一步尝试通过以下代码来缩短它

<%#Eval("Content").ToString().Length >= 170 ? Eval("Content").ToString().Substring(0, 170) : Eval("Content").ToString()%>

Does the needful, provided Database value is plain text and not HTML encoded one, which i have recently added, thus it stopped working. 我最近添加的需要提供的数据库值是纯文本而不是HTML编码的吗,因此它停止工作了。

Hence, i wish to know if I can use this following code to decode the encoded 因此,我想知道是否可以使用以下代码对编码后的视频进行解码

<%=System.Web.HttpUtility.HtmlDecode()%>

I Have tried doing this but no joy, can someone help or correct me if the following code is wrong(i think) 我曾尝试这样做,但没有喜悦,如果以下代码错误,有人可以帮助或纠正我吗(我认为)

<%=System.Web.HttpUtility.HtmlDecode(#Eval("Content"))%>

I believe you need: 我相信您需要:

<%# System.Web.HttpUtility.HtmlDecode(Eval("Content")) %>

The <%= is equivalent to Response.Write whereas <%# is data binding syntax which is what you need in this case. <%=等效于Response.Write<%#是数据绑定语法,在这种情况下,这是您所需要的。 Your hash prefix on the Eval call is not valid syntax. 您在Eval调用中的哈希前缀无效。

This is a useful reference to explain the difference between the various ASP.NET inline server tags: http://weblogs.asp.net/ahmedmoosa/embedded-code-and-inline-server-tags 这是解释各种ASP.NET内联服务器标签之间区别的有用参考: http : //weblogs.asp.net/ahmedmoosa/embedded-code-and-inline-server-tags

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

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