2013-05-21 68 views
0

我有一个textarea,然后我想呈现它。 我希望文本将以相同的分隔线或\ n保存。textarea保存将不会保存breakline

但它wouldnt。

继承人我的代码:

string content = Request.Form["content"]; 
      content = System.Web.HttpUtility.HtmlEncode(content); 
      UpdateContent(content, id); 

public void UpdateContent(string content, string id) 
{ 
    sql = "Update TBL_ZAC_SQUARES SET lotstext [email protected] where id = " + id; 

    connection = new SqlConnection(conn); 
    connection.Open(); 

    cmd = new SqlCommand(sql, connection); 
    cmd.Parameters.AddWithValue("@lotstext", content); 

    cmd.ExecuteNonQuery(); 

    connection.Close(); 
} 

然后我提出它像:

<td align="right" style="padding: 12px; font-family: Arial; font-size: 12pt; color: #000000"> 
             <div >  <%=dt_details.Rows[0][9].ToString() %></div> 
             </td> 
+0

保存在数据库中的值是多少? – mattytommo

+0

一个文本。这将保存与用户返回(br?或\ n?)它保存,但没有\ n或无论如何 – thormayer

回答

1

你是对内容进行编码保存在数据库之前,所以你必须之前显示在页面将其解码/ //...So你可以这样试试...

<div ><%=System.Web.HttpUtility.HtmlDecode(dt_details.Rows[0][9].ToString()) %></div> 
             </td> 

and Before Encoding content Write ...

content=content.Replace(Enviroment.NewLine,"<br/>"); 
+0

不起作用..仍然没有n/ – thormayer

+0

你能告诉我你的'内容'编码包含之前... \ r \ n .... –

+0

我只是想写例如..“嗨..”(然后我输入或返回)“你怎么做?” – thormayer