用 wrap="hard"属性  可以实现换行!

解决方案 »

  1.   

    你应该把\n替换成<br />就ok拉
    你的哪个替换肯定没有起到效果
      

  2.   

    //****************************************
            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);
            }
    //*********************************************