怎样在浏揽页面上保持输入时的文本格式 发布News时,将News 内容保存到数据库,怎样在浏揽页面上保持输入时的文本格式. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的问题其实就是把字符串格式转换为html识别的格式首先,保存到数据库的内容必须是要有格式的(一般都有)c#: string showTxt(string strPath) { string s = ""; string strGo=""; if (File.Exists(strPath)) { StreamReader sr=new StreamReader(strPath,Encoding.Default); while ((s = sr.ReadLine()) != null) //sr.Peek() >= 0 { strGo=strGo+s+"\r"; } sr.Close(); } strGo=strGo.Replace(" "," ").Replace("\r","<br>"); return strGo; } this.Label1.Text=@showTxt(strPath);客户端:<asp:Label id="Label1"style="WORD-BREAK:break-all"runat="server"Width="568px"Height="100px"ForeColor="DarkBlue" Font-Size="XX-Small" Font-Names="宋体" BorderStyle="None"></asp:Label> 我是把数据保存为文本文件,读取时做了一些处理( strGo=strGo+s+"\r";)从数据库读取也是一样,关键就是 strGo=strGo.Replace(" "," ").Replace("\r","<br>")把空格换成" ",换行换成"<br>",显示用lable,使用宋体字,效果最好。 对输入的内容进行编码:string s = System.Web.HttpUtility.HtmlEncode(TextBox1.Text);将s保存到数据库,查看时取出:Label1.Text = s; 100 求高手推荐好用灵活ASP.NET的CMS 求一个代替frameset将网页分为上中下三栏的代码 菜鸟求职!关于ASP.Net控件问题 关于统计文章管理系统中总文章数的问题 AJXA模版刷新延迟问题 AJAX.NET DragPanelExtender 如果PANEL 设置了位置,里面的控件不能正常被拖拉 word to html 求最近AspNetPager 2.0 的下载地址 很简单的却令我头疼的问题!!! 很急! 急问:关于SqlCommand的问题!!!!!???????? 请问怎么在表格(table)中插入一行呢(后台代码实现)?谢谢
首先,保存到数据库的内容必须是要有格式的(一般都有)
c#:
string showTxt(string strPath)
{
string s = "";
string strGo=""; if (File.Exists(strPath))
{
StreamReader sr=new StreamReader(strPath,Encoding.Default); while ((s = sr.ReadLine()) != null) //sr.Peek() >= 0
{
strGo=strGo+s+"\r";
}
sr.Close();
}
strGo=strGo.Replace(" "," ").Replace("\r","<br>");
return strGo;
}
this.Label1.Text=@showTxt(strPath);客户端:
<asp:Label id="Label1"style="WORD-BREAK:break-all"runat="server"Width="568px"Height="100px"
ForeColor="DarkBlue" Font-Size="XX-Small" Font-Names="宋体" BorderStyle="None"></asp:Label>
从数据库读取也是一样,关键就是 strGo=strGo.Replace(" "," ").Replace("\r","<br>")
把空格换成" ",换行换成"<br>",显示用lable,使用宋体字,效果最好。
string s = System.Web.HttpUtility.HtmlEncode(TextBox1.Text);
将s保存到数据库,查看时取出:
Label1.Text = s;