当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > Asp.Net中文本换行

ASP.NET
ASP.NET入门教程:ArrayList对象
ASP.NET入门教程:Hashtable对象
ASP.NET入门教程:SortedList对象
ASP.NET入门教程:把XML文件绑定到列表控件
ASP.NET入门教程:Repeater控件
ASP.NET入门教程:DataList控件
ASP.NET入门教程:数据库连接
ASP.NET入门教程:ASP.NET 2.0新特性
ASP.NET入门教程:ASP.NET 2.0母版页
ASP.NET入门教程:ASP.NET 2.0导航
ASP.NET入门教程:HTML服务器控件
ASP.NET入门教程:Web服务器控件
ASP.NET入门教程:Validation服务器控件
HTML服务器控件介绍:HtmlAnchor控件
HTML服务器控件介绍:HtmlButton控件
HTML服务器控件介绍:HtmlForm控件
HTML服务器控件介绍:HtmlGeneric控件
HTML服务器控件介绍:HtmlImage控件
HTML服务器控件介绍:HtmlInputButton控件
HTML服务器控件介绍:HtmlInputCheckBox控件

ASP.NET 中的 Asp.Net中文本换行


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 172 ::
收藏到网摘: n/a

刚刚入门学习ASP.NET的朋友,都会碰到把大量带有换行文本的内容显示时,不会自动换行的问题。本人现在把解决这一问题真正有效的办法告诉大家,共同学习:
在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
使用范例:
ContentTxt.Text = HtmlCode(Rs.Item("NewsContent"))
注:.ContentTxt为Label标签控件;Rs.Item("NewsContent")为读取数据库表中的记录集。
以上代码可在我的.NET博客系统中找到详细代码。
在C#中:
private String HtmlCode(string TString)
{
if (TString != null)
{
TString = TString.Replace("\r", "<br>");
TString = TString.Replace(" ", " ");
return TString;
}
else
{
return TString="无内容";
}
}
使用范例:
this.ContentTxt.Text = HtmlCode(NewsTab.Rows[0]["ContentTxt"].ToString());
注:.ContentTxt为Label标签控件;NewsTab.Rows[0]["ContentTxt"].ToString()为读取数据库表中的记录集。
以上代码可在我的.NET新闻系统中找到详细代码。
http://lixyvip.cnblogs.com/archive/2006/03/30/362593.html