Response.Write从数据库打印文本为HTML [英] Response.Write print text from database as HTML

查看:111
本文介绍了Response.Write从数据库打印文本为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将文本从textarea存储到我的数据库中。这个文本可以包含新的行,特殊字符等。但是我想确保当我使用response.write显示它时,它确实出现在textarea控件中。我想这样做的原因是因为我想给用户一个打印视图表单。下面的解决方案不起作用。使用ASP.NET/C#



eg

  foreach(DataRow row在dview.Table.Rows)
{
Response.Write(< tr>);
Response.Write(String.Format(< td> {0}< br />< br />< / td>,row [1] .ToString()。Replace \\\
,< br />)));
Response.Write(< / tr>);

谢谢

解决方案你可以在< pre>< / pre> 块中显示输出,它将保留所有的空白,包括多个空格,换行符等。



建议使用HTML编码,这样数据中的任何尖括号都不会破坏输出HTML。


I'm storing text from a textarea to my database. This text can contain new lines, special characters etc. However I want to make sure that when I show it using response.write, it comes out exactly as if it was to show in the textarea control. The reason why I want to do this is because I want to give the user a print view form. The solution below does not work. Using ASP.NET/C#

e.g

foreach (DataRow row in dview.Table.Rows)
{
Response.Write("<tr>");
                    Response.Write(String.Format("<td>{0}<br/><br/></td>",   row[1].ToString().Replace("\n", "<br/>")));
                    Response.Write("</tr>");

Thanks

解决方案

You could display the output inside a <pre></pre> block which will preserve all whitespace, including multiple spaces, newlines, etc.

HTML encoding is recommended so any angle brackets in the data don't break the output HTML.

这篇关于Response.Write从数据库打印文本为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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