写个方法转换一下:/// <summary>
/// 替换html中的特殊字符
/// </summary>
/// <param name="theString">需要进行替换的文本。</param>
/// <returns>替换完的文本。</returns>
public string HtmlEncode(string theString)
{
theString=theString.Replace(">", "&gt;");
theString=theString.Replace("<", "&lt;");
theString=theString.Replace("  ", " &nbsp;");
theString=theString.Replace("  ", " &nbsp;");
theString=theString.Replace("\"", "&quot;");
theString=theString.Replace("\'", "&#39;");
theString=theString.Replace("\n", "<br/> ");
return theString;
} /// <summary>
/// 恢复html中的特殊字符
/// </summary>
/// <param name="theString">需要恢复的文本。</param>
/// <returns>恢复好的文本。</returns>
public string HtmlDiscode(string theString)
{
theString=theString.Replace("&gt;", ">");
theString=theString.Replace("&lt;", "<");
theString=theString.Replace("&nbsp;"," ");
theString=theString.Replace(" &nbsp;","  ");
theString=theString.Replace("&quot;","\"");
theString=theString.Replace("&#39;","\'");
theString=theString.Replace("<br/> ","\n");
return theString;
}不知道能帮你么?

解决方案 »

  1.   

    pupstar  照你的方法还是一样啊,这是放在显示那个页面吗??
      

  2.   

    用freetextbox的话,值不用转换的。
      

  3.   

    直接绑定在datalist里输出看看效果。
    我用freetextbox就没转换过啊。
    我开始也认为是要转换呢。但后来发现不需要。
    你这样输出的原因可能是浏览器没有解释执行,你看看为什么浏览器为什么没有解释执行的原因吧。
      

  4.   

     我上面就是绑定在datalist里输出的效果啊晕,怎么办啊,为什么你们的不需要转啊,是哪个版本啊,能不能提我一个啊,
      

  5.   

    我用gridview的时候也遇到了这个问题,我的解决方法是在gridview中的RowDataBound里把要显示html效果列的数据进行replace
    With e.Row
         .Cells(4).Text = .Cells(4).Text.Replace("&lt;", "<")
         .Cells(4).Text = .Cells(4).Text.Replace("&gt;", ">")
    End With
    不知道是否能帮你解决问题。
      

  6.   

    我的代码如下,大家看看有没有问题    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Contents") %>'></asp:TextBox>&nbsp;<br />
            <ftb:freetextbox id="FreeTextBox1" runat="server" Width="600px" ToolbarLayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu|Bold,Italic,
    Underline,Strikethrough;Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,
    JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,
    InsertImageFromGallery,InsertRule|Cut,Copy,Paste;Undo,Redo,Print,Preview" ButtonSet="Office2003" Language="zh-CN" StripAllScripting="True"></ftb:freetextbox>
            <br />
            <br />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
        </form>       SqlConnection cn;
            String strConnection = ConfigurationSettings.AppSettings["ConnectionString"];
            cn = new SqlConnection(strConnection);
            SqlCommand cm = new SqlCommand("freeproc", cn);
            cm.CommandType = CommandType.StoredProcedure;        cm.Parameters.Add(new SqlParameter("@utitle", SqlDbType.VarChar, 50));
            cm.Parameters.Add(new SqlParameter("@unews", SqlDbType.NVarChar,250));
            cm.Parameters["@utitle"].Value = TextBox1.Text;
            cm.Parameters["@unews"].Value = FreeTextBox1.Text;
            cm.Connection.Open();
      

  7.   

    这个问题听容易解决的,我最近也在做这一块,给我的给你参考下吧
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!Page.IsPostBack)
    {
    newsid = Request.Params["InfoId"];
    SqlConnection myConnection = new SqlConnection(DB.strConn);    
    SqlDataAdapter myCommand = new  SqlDataAdapter("SELECT * FROM Inform WHERE InfoId="+newsid, myConnection); 
    DataSet ds = new DataSet(); 
    myCommand.Fill(ds, "notice"); 
    dr = ds.Tables["notice"].Rows[0];
    title.Text=dr["Infotitle"].ToString();
    title.Font.Name="宋体";
    this.date.Text=dr["Infodate"].ToString();
    string strcontent=dr["Infocontent"].ToString();
    string str=Server.HtmlDecode(strcontent); //关键是这,实现转换  
    this.content.Text=str; }
    }
      

  8.   

    问题是我在gridview时用的是SqlDataSource
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound">
                <Columns>
                    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                        SortExpression="ID" />
                    <asp:BoundField DataField="title" HeaderText="title" SortExpression="title" />
                    <asp:BoundField DataField="news" HeaderText="news" SortExpression="news" />
                    <asp:BoundField DataField="date" HeaderText="date" SortExpression="date" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:emapgoConnectionString6 %>"
                SelectCommand="SELECT [ID], [title], [news], [date] FROM [free] ORDER BY [ID]"></asp:SqlDataSource>
        
        </div>
        </form>
      

  9.   

    加入删除格式按钮 
     function  ClearWord()
         {
         
    var  text  =  FTB_API['FreeTextBox1'].GetHtml();text=text.replace(/<FONT[^>]*>/gi,"");
    text=text.replace(/<\/FONT>/gi,"");
    text=text.replace(/<U>/gi,"");
    text=text.replace(/<\/U>/gi,"");
    text=text.replace(/<H[^>]*>/gi,"");
    text=text.replace(/<\/H[^>]*>/gi,"");//  Change  these  tags.
    text=text.replace(/<B[^>]*>/gi,"&bold");
    text=text.replace(/<\/B[^>]*>/gi,"&cbold");
    text=text.replace(/<STRONG[^>]*>/gi,"&bold");
    text=text.replace(/<\/STRONG[^>]*>/gi,"&cbold");text=text.replace(/<I[^>]*>/gi,"&ital");
    text=text.replace(/<\/I[^>]*>/gi,"&cital");
    text=text.replace(/<EM[^>]*>/gi,"&ital");
    text=text.replace(/<\/EM[^>]*>/gi,"&cital");text=text.replace(/<UL[^>]*>/gi,"&ultag");
    text=text.replace(/<LI[^>]*>/gi,"&litag");
    text=text.replace(/<OL[^>]*>/gi,"&oltag");
    text=text.replace(/<\/OL>/gi,"&olctag");
    text=text.replace(/<\/LI>/gi,"&lictag");
    text=text.replace(/<\/UL>/gi,"&ulctag");text=text.replace(/<P[^>]*>/gi,"&parag");
    text=text.replace(/<\/P>/gi,"");/*
    text=text.replace(/?gi,'\"');
    text=text.replace(/?gi,'\"');
    text=text.replace(/?gi,'\"');
    text=text.replace(/mailto:/gi,'\"');
    text=text.replace(/?g,"&Auml;");
    text=text.replace(/?g,"&Ouml;");
    text=text.replace(/?g,"&Uuml;");
    text=text.replace(/?g,"&auml;");
    text=text.replace(/?g,"&ouml;");
    text=text.replace(/?g,"&uuml;");
    text=text.replace(/?gi,"&szlig;"); 
    */text=text.replace(/&lt;[^>]&gt*;/gi,"");
    text=text.replace(/&lt;\/[^>]&gt*;/gi,"  ");
    text=text.replace(/<o:[^>]*>/gi,"");
    text=text.replace(/<\/o:[^>]*>/gi,"");
    text=text.replace(/<\?xml:[^>]*>/gi,"");
    text=text.replace(/<\/?st[^>]*>/gi,"");
    text=text.replace(/<[^>]*</gi,"<");
    text=text.replace(/<SPAN[^>]*>/gi,"");
    text=text.replace(/<SPAN[^class]*>/gi,"");
    text=text.replace(/<\/SPAN>/gi,"");
    //text=text.replace(/<\/A>/gi,"");//  Clear  the  inner  parts  of  other  tags.//text=text.replace(/style=[^>]*"/g,'  ');
    //text=text.replace(/style=[^>]*'/g,"  ");
    text=text.replace(/style=[^>]*>/g,">");
    text=text.replace(/lang=[^>]*>/g,">");
    text=text.replace(/name=[^>]*  /g,"");
    text=text.replace(/name=[^>]*>/g,">");
    text=text.replace(/<A[^>]*>/g,"");//text=text.replace(/<p[^>]*>/gi,"<p>");
    //  Put  the  tags  back
    text=text.replace(/&bold/g,"");
    text=text.replace(/&cbold/g,"");text=text.replace(/&ital/g,"<EM>");
    text=text.replace(/&cital/g,"</EM>");text=text.replace(/&ultag/g,"<UL>");
    text=text.replace(/&litag/g,"<LI>");
    text=text.replace(/&oltag/g,"<OL>");
    text=text.replace(/&olctag/g,"<\/OL>"); 
    text=text.replace(/&lictag/g,"<\/LI>");
    text=text.replace(/&ulctag/g,"<\/UL>");text=text.replace(/&parag/g,"<BR>");
    FTB_API['FreeTextBox1'].SetHtml(text);
    //document.Form1.FreeTextBox1.innerHTML  =  text;
    }
      

  10.   

    你绑定可以 用label,然后<%# Bind('你的数据库字段名字')%>可能不会出现你说的那种情况吧。