不能换行,请大家帮忙.............................. 用 wrap="hard"属性 可以实现换行! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你应该把\n替换成<br />就ok拉你的哪个替换肯定没有起到效果 //**************************************** public string texttohtml(string chr)//把从键盘输入的“空格和回车”转化成HTML语言中的空格和回车 { if (chr == null) return ""; chr = chr.Replace("<", "amp;lt"); chr = chr.Replace(">", "amp;gt"); chr = chr.Replace("\n", "<br>"); chr = chr.Replace(" ", "amp;nbsp;"); return (chr); } public string rettexttohtml(string chrr)//把HTML语言中的空格和回车,转化成键盘上的空格和回车 { if (chrr == null) return ""; chrr = chrr.Replace("amp;lt", "<"); chrr = chrr.Replace("amp;gt", ">"); chrr = chrr.Replace("<br>", "\n"); chrr = chrr.Replace("amp;nbsp;", " "); return (chrr); } //**************************************** protected void Button2_Click(object sender, EventArgs e) //添充数据到数据库,调用texttohtml(string chr)方法 { string acontext = this.TextBox3.Text; string texts = texttohtml(acontext); string insetsql = "insert into T_Content(title,contents)values('" + this.TextBox2.Text.Trim() + "','" + texts + "')"; SqlConnection con = new SqlConnection(strcon); SqlCommand com = new SqlCommand(insetsql,con); con.Open(); com.ExecuteNonQuery(); con.Close(); Response.Write("<script>alert("添加成功");</script>"); } protected void Button3_Click(object sender, EventArgs e)//显示数据 调用rettexttohtml(string chrr)方法 { string showstr = "select * from T_Content where id=12"; SqlConnection con = new SqlConnection(strcon); SqlCommand com = new SqlCommand(showstr,con); con.Open(); SqlDataReader sdr = com.ExecuteReader(); sdr.Read(); string t3 =Convert.ToString(sdr.GetValue(2)); sdr.Close(); con.Close(); this.TextBox3.Text = rettexttohtml(t3); }//********************************************* C#去除字符串中特定字符及之后的字符 关于Petshop中的DALFactory的问题? 未将对象实例化? 正在做一个oa系统,想请教一下各位,短消息提醒应该使用什么窗口? 在javascript中如何遍历HtmlTable? 那里错了,怎么简化这个程序? JS 很 html 的问题 这个CSS样式的值用Jquery应该怎么修改??? 请微软件专家和VB。NET专家帮我解决一下。我编写一个ASP.NET程序时出现下列错误 从工具箱中放一个DataGrid入Web Forms中,预览时为什么显示不出来? 这个分页存储过程该怎么改? webService
你的哪个替换肯定没有起到效果
public string texttohtml(string chr)//把从键盘输入的“空格和回车”转化成HTML语言中的空格和回车
{
if (chr == null)
return "";
chr = chr.Replace("<", "amp;lt");
chr = chr.Replace(">", "amp;gt");
chr = chr.Replace("\n", "<br>");
chr = chr.Replace(" ", "amp;nbsp;");
return (chr);
}
public string rettexttohtml(string chrr)//把HTML语言中的空格和回车,转化成键盘上的空格和回车
{
if (chrr == null)
return "";
chrr = chrr.Replace("amp;lt", "<");
chrr = chrr.Replace("amp;gt", ">");
chrr = chrr.Replace("<br>", "\n");
chrr = chrr.Replace("amp;nbsp;", " ");
return (chrr);
}
//****************************************
protected void Button2_Click(object sender, EventArgs e) //添充数据到数据库,调用texttohtml(string chr)方法
{
string acontext = this.TextBox3.Text;
string texts = texttohtml(acontext);
string insetsql = "insert into T_Content(title,contents)values('" + this.TextBox2.Text.Trim() + "','" + texts + "')";
SqlConnection con = new SqlConnection(strcon);
SqlCommand com = new SqlCommand(insetsql,con);
con.Open();
com.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert("添加成功");</script>");
}
protected void Button3_Click(object sender, EventArgs e)//显示数据 调用rettexttohtml(string chrr)方法
{
string showstr = "select * from T_Content where id=12";
SqlConnection con = new SqlConnection(strcon);
SqlCommand com = new SqlCommand(showstr,con);
con.Open();
SqlDataReader sdr = com.ExecuteReader();
sdr.Read();
string t3 =Convert.ToString(sdr.GetValue(2));
sdr.Close();
con.Close();
this.TextBox3.Text = rettexttohtml(t3);
}
//*********************************************