【问题标题】:New Line In TextArea from c# [duplicate]来自c#的TextArea中的新行[重复]
【发布时间】:2014-12-16 14:24:31
【问题描述】:

我正在开发一个 ASP.NET 应用程序。文本取自数据库,其中换行符存储为'\r\n',我将文本放入启用了 MultiLine 的 TextBox 中。 但是,我似乎无法在 TextBox 中换行

string description = description.Replace("\\r\\n", "<br/>");
lblDescriptionV.Text = description;

我尝试将换行符替换为:&lt;br/&gt;&amp;#13;&amp;#10;&amp;#10;,但该值只是打印到 texbox 中。 所以它会显示为:"Line 1&lt;br/&gt;line 2"

【问题讨论】:

标签: c# asp.net


【解决方案1】:
<asp:TextBox runat="server" ID="txtArea" TextMode="MultiLine" Rows="10" />

后面的代码:

protected void Page_Load(object sender, EventArgs e)
{
    txtArea.Text = "Hello\nThere\nFriend";
}

因此您需要以下内容:

string description = "Hello\\r\\nThere\\r\\nFriend";
description = description.Replace("\\r\\n", "\n");

注意:您不能在标签中输入分隔符 (lblDescriptionV)

【讨论】:

  • 谢谢。有点奇怪,我到处都说用这个和那个替换'\ n'。但它现在可以工作了:) PS。 lblDescriptionV 实际上是一个 textarea - 我的命名约定有一个小错误......
【解决方案2】:

将其替换为Environment.NewLine

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 2011-04-24
    • 1970-01-01
    相关资源
    最近更新 更多