zoukankan      html  css  js  c++  java
  • GrideView 实现显示超长数据并转码

    前台grideview中显示一个字段的(一个TemplateField)代码:

     <asp:TemplateField HeaderText="景点内容">
                        <ItemTemplate>
                            <asp:Label ID="lblNewsContent" runat="server"
                                Text='<%#Pd_Str(Eval("f_jdNewsContent").ToString(),10) %>  ' ></asp:Label> <%--Pd_Str 是后台的一个方法--%>
                        </ItemTemplate>

    </asp:TemplateField>

    后台代码:

    using System.Text.RegularExpressions;

    //实现显示用“……”代替具有超级链接类型字段的超长数据
            protected string Pd_Str(string str, int length)
            {
                str = NoHTML(str);
                if (str.Length > length)
                {
                    str = str.Substring(0, length) + "……";
                }
                return str;
            }
            //从数据库里读取的数据去掉Html标签
            public static string NoHTML(string Htmlstring)
            {
                //删除脚本  
                Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
                //删除HTML  
                Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);

                Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "   ", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);

                Htmlstring.Replace("<", "");
                Htmlstring.Replace(">", "");
                Htmlstring.Replace("\r\n", "");
                Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

                return Htmlstring;
            }

  • 相关阅读:
    NOI2015 品酒大会
    网络流算法进阶详解
    ZROJ 1267 我要打数论
    后缀自动机构建图解
    WC集训DAY2笔记 组合计数 part.1
    最小割的数学模型
    二次剩余学习笔记
    Hadoop:eclipse配置hadoop-eclipse-plugin(版本hadoop2.7.3)
    MapReduce:实现文档倒序排序,且字符串拼接+年+月+日
    MapReduce:汇总学生表和成绩表为----学生成绩表
  • 原文地址:https://www.cnblogs.com/rongxiaoya/p/2673129.html
Copyright © 2011-2022 走看看