在发表时,提交按钮的事件里是这样的:
string cont = Server.HtmlEncode(tbContent.Text.ToString().Replace("'", "!"));-------------cont是发表的内容;
在显示位置绑定时是这样的:
<asp:Label ID="Label4" runat="server" Text='<%# Server.HtmlDecode(Eval("content").ToString()) %>'></asp:Label>
但是,在发表时,明明是有换行的,到了显示的地方却都在一行了!这是怎么回事啊?
拜托各位了!!

解决方案 »

  1.   

    public static string FullHTMLEncode(string inputVal)
    {
    if(inputVal != null)
    {
    inputVal = inputVal.Replace(">","&gt;");
    inputVal = inputVal.Replace("<","&lt;");
    inputVal = inputVal.Replace("\'","&apos;");
    inputVal = inputVal.Replace("\"","&quot;");
    inputVal = inputVal.Replace(string.Format("{0}",(char)32), "&nbsp;");
    inputVal = inputVal.Replace(string.Format("{0}",(char)9),"&nbsp;");
    inputVal = inputVal.Replace(string.Format("{0}",(char)34),"&quot;");
    inputVal = inputVal.Replace(string.Format("{0}",(char)39),"&#39;");
    inputVal = inputVal.Replace(string.Format("{0}",(char)13),"");
    inputVal = inputVal.Replace(string.Format("{0}",(char)10)+string.Format("{0}",(char)13),"</p><p> ");
    inputVal = inputVal.Replace(string.Format("{0}",(char)10), "<br/> ");
    }
    return inputVal;
    }
    把字符用以上函数进行Html编码就可以了。
      

  2.   

    多谢xiaomatian(趴趴熊◎%#……※×) ( ) 信誉:100    
    ----------------
    问题解决!
    再次感谢!马上给分!分少别介意,但是我的全部,仅表心意!