StringBuilder-Append解决DIV字符串输出数据库数据 - TOMMYHU - 专注互联网开发及运营技术,提供相关资料及软件下载,奇趣网络时事评论!
May 17

StringBuilder-Append解决DIV字符串输出数据库数据 不指定

tommyhu , 10:34 , ASP.NET , Comments(0) , Trackbacks(0) , Reads(8061) , Via Original Large | Medium | Small

using System.Text;
protected void DataHuanBind()
    {
        //焦点新闻
        StringBuilder StrSql = new StringBuilder();

        StrSql.Append("select top 3 id,title,newsurl,lanternurl,classid from hotel_news where ");
        StrSql.Append("ischeck=1 and isenglish=0 and islantern=1");
        StrSql.Append(" order by id desc");

        SqlDataReader sdr = SqlHelper.ExecuteReader(StrSql.ToString());

        StringBuilder builder1 = new StringBuilder();
        StringBuilder builder2 = new StringBuilder();
        StringBuilder builder3 = new StringBuilder();

        while (sdr.Read())
        {
            builder1.Append(",");
            builder1.Append(sdr.GetString(sdr.GetOrdinal("lanternurl")));
            builder2.Append(",");
            builder2.Append("<a class=\"bla\" href=\"");
            builder2.Append(GetUrl(sdr.GetString(sdr.GetOrdinal("newsurl")), sdr.GetInt32(sdr.GetOrdinal("classid"))));
            builder2.Append("\" target=\"_blank\"><strong>");
            builder2.Append(sdr.GetString(sdr.GetOrdinal("title")));
            builder2.Append("</strong></a>");
            builder3.Append(",");
            builder3.Append(GetUrl(sdr.GetString(sdr.GetOrdinal("newsurl")), sdr.GetInt32(sdr.GetOrdinal("classid"))));
        }
        sdr.Close();

        if (builder1.Length > 0)
        {
            builder1.Remove(0, 1);
            builder2.Remove(0, 1);
            builder3.Remove(0, 1);

            picurl = builder1.ToString().Split(',');
            titleurl = builder2.ToString().Split(',');
            newsurl = builder3.ToString().Split(',');
            if (picurl.Length != 3)
            {
                picurl = "nothing,nothing,nothing".Split(',');
                titleurl = "nothing,nothing,nothing".Split(',');
                newsurl = "nothing,nothing,nothing".Split(',');
            }
        }
        else
        {
            picurl = "nothing,nothing,nothing".Split(',');
            titleurl = "nothing,nothing,nothing".Split(',');
            newsurl = "nothing,nothing,nothing".Split(',');
        }
    }



参考:
http://521dd.blog.sohu.com/entry/4567837/
http://blog.csdn.net/erroraspx/archive/2010/02/14/5308712.aspx
▲返回顶部
Last modified by tommyhu on2010/05/17 10:35

Add a comment

Nickname

emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot