asp.net如何将数据库的html代码调用出来时进行显示

我用Asp.Net开发新闻网站的时候,首先在FCKEditor在线编辑器上操作,把图片上传放在服务器上,用一个数据库来保存新闻,新闻内容是图文混排的!保存的都是代码,然后... 我用Asp.Net开发新闻网站的时候,首先在FCKEditor在线编辑器上操作,把图片上传放在服务器上,用一个数据库来保存新闻,新闻内容是图文混排的!保存的都是代码,然后用DetailsView或GridView控件进行显示时 要怎么样才能把HTML代码去掉显示成原来排版时的图文混排呢? 谢谢.... 展开
 我来答
百度网友2e53a4a
2010-10-12 · TA获得超过3753个赞
知道大有可为答主
回答量:4068
采纳率:0%
帮助的人:2082万
展开全部
public static string Nohtml(string Htmlstr, int leng)
{
string Htmlstring = string.Empty;
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"-->", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"<!--.*", "", RegexOptions.IgnoreCase);

Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&#(\d+);", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "xp_cmdshell", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, ">", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "<", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "<p>", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "</p>", "", RegexOptions.IgnoreCase);
////删除与数据库相关的词
//Htmlstring = Regex.Replace(Htmlstring, "select", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "insert", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "delete from", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "count''", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "drop table", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "truncate", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "asc", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "mid", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "char", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "xp_cmdshell", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "exec master", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "net localgroup administrators", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "and", "", RegexOptions.IgnoreCase);
Htmlstring = SubString(Htmlstr, leng);

return Htmlstring;
}

输出的时候先处理一下。 但是不要改动数据库不然变不回去了。
理工爱好者

2010-10-12 · TA获得超过2284个赞
知道大有可为答主
回答量:5249
采纳率:97%
帮助的人:676万
展开全部
如果去掉了HTML, 更不可能变成原来排版的样子了
一般直接输出就可以了
如果入库的时候进行了HtmlEncode, 选出后注意先HtmlDecode,再输出
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式