在数据库中保存格式化文本时出现问题 [英] Problem in Save formatted text in database

查看:116
本文介绍了在数据库中保存格式化文本时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我想使用asp.net中的c#将格式化的文本保存在数据库中.
下面的代码将文本保存在数据行中:

Hi .
i want to save formatted text in database using c# in asp.net .
below code save text in data row :

dr.fContent=txtContent.Text;


现在我想从表中获取我的内容,并通过数据绑定在Lable Control中表示:


and now i want to fetch my content from table and represent in Lable Control by Data binding :

<asp:Label ID="lblContent" runat="server" Text='<%# Eval("fContent")%>'></asp:Lable>



但是如果我输入格式化的文本不能正常工作
例如,如果我输入:
1
2
3
然后显示123!



but if i enter formatted text doesn''t work correctly
for example if i enter :
1
2
3
then show 123 !

推荐答案

这是因为"\ n"对浏览器没有任何意义-只能删除空白.考虑使用string.Replace将其更改为HTML换行符:
That is because ''\n'' means nothing to the browser - it is just whitespace which can be removed. Consider using string.Replace to change it to an HTML newline:
dr.fContent = txtContent.Text.Replace("\n", "<br />");


Hellow,通常,文本框不允许保存格式化的文本.而是使用Richtext Box控件,该控件将允许您输入格式化的文本并将其取回.但您仍然希望以格式化的方式进行操作..您已将其作为html标签输入,例如文本
等..
Hellow, Generally, textbox won''t allow to save formatted text. rather use richtext box control which will allow you to enter the formatted text the retrieve it back. but still you want to do it in a formatted way.. you have enter it as html tags like Text
and so on..


您可以使用RichTextBox代替TextBox.请参阅CodeProject文章,网址为: C#-在RichTextBox中设置文本格式通过解析RTF格式(RTF) [
Instead of TextBox, you can use RichTextBox. Refer CodeProject article at: C# - Formatting Text in a RichTextBox by Parsing the Rich Text Format (RTF)[^]


这篇关于在数据库中保存格式化文本时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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