Friends who have just started learning ASP.NET will encounter the problem that when displaying a large amount of content with line breaks, the lines will not wrap automatically. I will now tell you the truly effective way to solve this problem and learn together:
In VB.NET:
1 Function HtmlCode()Function HtmlCode(ByVal fString)
2 If fString <> "" Then
3 fString = Replace(fString, Chr(13), "")
4 fString = Replace(fString, Chr(10) & Chr(10), "</P><P>")
5 fString = Replace(fString, Chr(10), "<BR>")
6 HtmlCode = fString
7 End If
8 End Function
9
Usage example:
ContentTxt.Text = HtmlCode(Rs.Item("NewsContent"))
Note: .ContentTxt is the Label label control; Rs.Item("NewsContent") is the record set that reads the database table.
The detailed code for the above code can be found in my .NET blog system.
In C#:
private String HtmlCode(string TString)
{
if (TString != null)
{
TString = TString.Replace("r", "<br>");
TString = TString.Replace(" ", " ");
return TString;
}
else
{
return TString="No content";
}
}
Usage example:
this.ContentTxt.Text = HtmlCode(NewsTab.Rows[0]["ContentTxt"].ToString());
Note: .ContentTxt is Label label control; NewsTab.Rows[0]["ContentTxt"].ToString() is Read a record set from a database table.
The detailed code for the above code can be found in my .NET news system.
Source: Li Xiyuan BLOG