This problem should be a very simple one. To be honest, when I spent two hours on it, when I came out later, I was really confused. I hope you can give me a reminder of this process.
I. VB. NET ASP. NET problem Restoration
When I edit a piece of data, we enter the editing page, for example, the Work Araound field in the following page.
I have entered some content for these fields. I press enter and divide it into sections. However, when we save the Edit page, the result is as follows:
We can clearly see that the displayed value does not have segments. The display effect is unfriendly.
Solution:
Keyword: vbCrLf (VB is used because of project requirements. NET and VS2005, let everyone laugh), I get through the following code every time you press enter, then I first get the carriage return, and then convert it into "| ", in this way, the data is stored in the database. (In fact, there is a drawback here: "|" is an unusable character .)
Copy codeThe Code is as follows:
Dim strTextArea As String = Replace (TextArea1.Value, vbCrLf, "|") is equivalent to the following: Dim strTextArea As String = TextArea1.Value. Replace (vbCrLf, "| ")
Then, when we read data from the database, we should replace it with the following:
Copy codeThe Code is as follows:
Label1.Text = strTextArea. Replace ("|", "<br> ")
Then, here we get to the basic OK. In the middle of the page, we seem to have achieved the expected results.
In fact, there is another problem here, that is, when every line is long, the following bug will appear. No. The line break is not displayed for the fields that have been exceeded. It is hard to see.
We needParent element of the current elementAdd a style.Word-break: break-allAnd then it will automatically wrap the line.
Copy codeThe Code is as follows:
<TD style = "WIDTH: 451px; word-break: break-all">
<Textarea id = "txtReleaseNoteComment" cols = "51" rows = "10" runat = "server" visible = "false"> </textarea>
<Asp: Label ID = "lbl_releaseNotedComment" runat = "server" Text = "" Visible = "False" width = "0000px"> </asp: Label>
</TD>
The result is as follows:
Comments: I feel like it's a bend. But let's use it first. Submit it first!
Ii. What about C # ASP. NET?
The processing is much simpler. Environment: V. S. 2010
Test code:
Copy codeThe Code is as follows:
<Asp: TextBox ID = "TextBox1" runat = "server" Height = "105px" TextMode = "MultiLine"
Width = "320px"> </asp: TextBox>
<Asp: Button ID = "Button1" runat = "server" onclick = "button#click" Text = "Button"/>
<Br/>
<Asp: Label ID = "Label1" runat = "server" Text = "Label"> </asp: Label>
Then, we set a breakpoint at the Button,
As shown above, I did not set anything, so I automatically recognized the line break: \ r \ n. Then we can handle it well:
Copy codeThe Code is as follows:
Protected void button#click (object sender, EventArgs e)
{
Label1.Text = TextBox1.Text. Replace ("\ r \ n", "<br> ");
}
OK.
You can.
Iii. Winform
In Winform, it's easier. You don't need to process it. It's okay to assign the value to textbox directly.
Copy codeThe Code is as follows:
Label1.Text = textBox1.Text;
Ah. You have to feel the advanced technology.