我在项目中使用了FCKEditor控件,将它的值存入到了数据库,里面是有样式代码的。当读取出来将数据绑定到GridView时样式代码始终去不掉。用Server.HtmlEcode不管用,有什么办法可以做到绑定的时候没有样式代码出现,只显示文本吗?

解决方案 »

  1.   

    /// <summary>
        /// 去掉html标记
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        protected static string ConvertGettext(string str)
        {
            Regex regex = new Regex(@"\<(.*?)\>", RegexOptions.IgnoreCase);        return regex.Replace(str, "").Replace("&nbsp;", "").Replace("\n", "").Replace("\r", "");
        }
      

  2.   

    &lt;p style=&quot;text-align: center&quot;&gt;&lt;/p&gt; &lt;p style=&quot;text-align: center&quot;&gt;<font face="Calibri">AG</font>&lt;/p&gt,里面有这种代码,楼上的好想不好用
      

  3.   

    GridView使用模板列 lable显示数据即可
      

  4.   

    哎呦我的神啊,不会转一下再用么?  String s = @"&lt;p style=&quot;text-align: center&quot;&gt;&lt;/p&gt; &lt;p style=&quot;text-align: center&quot;&gt;<font face=Calibri>AG</font>&lt;/p&gt>";  s = Server.HtmlDecode(s);  Regex regex = new Regex(@"\<(.*?)\>", RegexOptions.IgnoreCase);
      s =  regex.Replace(s, "").Replace("&nbsp;", "").Replace("\n", "").Replace("\r", "");
      

  5.   

    模板列 ,litear控件,html编码
    或者html的<pre></pre>