ASP.Net文字与多行,文本框断行保存在数据库中 [英] ASP.Net Text with LineBreak from Multi-Line-TextBox to save in a database

查看:107
本文介绍了ASP.Net文字与多行,文本框断行保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有PrivateMessage-系统在我的新社区页。

I have PrivateMessage-System in my new Community-Page.

我有一个多行,文本框的私人邮件的文本。
我保存这个文本字符串,这个字符串在NTEXT SQL-Coloumn。
我在一个字符串读取来自NTEXT SQL-柱子该文本并显示在一个标签。

I have a Multiline-Textbox for the Text of a private message. I save this text in a string, this string in a ntext SQL-Coloumn. I read this text from the ntext SQL-Coloum in a string and show it in a label.

当我有5个换行,在我的多行文本框输入-Key,换行符将消失在标签中。

When I have 5 linebreaks with the "Enter"-Key in my Multi-line-textbox, the linebreaks will disappeared in the label.

我不知道他们失去了什么,我做错了。
任何想法?

I don't know where they gone lost and what I am doing wrong. any idea?

推荐答案

首先它实际上是节约了换行到你的餐桌?如果是这样,是什么把它们保存为,如:\\ r \\ n或CRLF还是什么?

First of all is it actually saving the line breaks to your table? If so, what does it save them as, eg \r\n or CRLF or what?

您标签输出HTML,所以这将创建一个突破的唯一的事情是< BR /> 标记。所以,你需要查找和替换无论是保存在数据库中:

Your label outputs html, so the only thing that will create a break is a <br /> tag. So you need to find and replace whatever is saved in the database:

Label1.Text = someDatabaseText.Replace("\r\n", "<br />");

甚至更好,做.Replace()将其保存到数据库之前:

Or even better, do the .Replace() before you save it to the database:

someDatabaseField = TextBox1.Text.Replace("\r\n", "<br />");

这篇关于ASP.Net文字与多行,文本框断行保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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