zoukankan      html  css  js  c++  java
  • StringBuilder 在后台动态输出 html 代码

            protected string bnaner()
            {
                StringBuilder sb = new StringBuilder();
                bool ifurl = false;
                string tpname = "hoticp.swf";
                string tpname2 = "titlebg.jpg";
                string tplink = "http://www.sohu.com";

                    if (ifurl == true)
                    {
                        sb.AppendFormat("<object width=\"948\" height=\"80\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\">" +
                                  "<param value=\"/tp/{0}\" name=\"movie\"/>" +
                                  "<param value=\"high\" name=\"quality\"/>" +
                                  "<param value=\"false\" name=\"menu\"/>" +
                                  "<param value=\"opaque\" name=\"wmode\"/>" +
                                  "<embed width=\"948\" height=\"80\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" false=\"\" wmode=\"opaque\" src=\"/tp/{0}\"/>" +
                                  "</object>", tpname);
                    }
                    else
                    {
                        sb.AppendFormat("<a href=\"{1}\" target=\"_blank\" onFocus=\"this.blur()\"><img src=\"/tp/{0}\" width=\"948\" height=\"80\"></a>", tpname2, tplink);
                    }

                
                return sb.ToString();
            }

            protected string classad(int c1)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
                SqlDataReader rs = newdb.CommonExecuteReader("select top " + c1 + " Title,ID,DateAndTime from News  order by ID desc");
                while (rs.Read())
                {
                    sb.AppendFormat("<tr><td>{2}</td><td><a href=\"abc.aspx?id={1}\" target=\"_blank\">{0}</a></td></tr>", rs[0], rs[1], Convert.ToDateTime(rs[2]).ToString("M-d"));
                }
                sb.AppendFormat("</table>");
                rs.Close();
                return sb.ToString();
            }

    前台调用

        <table border="1" cellpadding="0" cellspacing="0" width="100%" align="center">
            <tr>
                <td>
                <%=bnaner()%>
                </td> 
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    
                       <%=classad(5%>
                    
                </td> <td>
                </td>
            </tr>                         </table>
  • 相关阅读:
    Excel如何关闭进程
    Excel_To_DataTable
    将本地项目上传到Github
    对于session,request,cookie的理解
    static的使用
    Java事件监听的四种实现方式
    静态网页和动态网页
    ps -ef|grep详解
    linux ls -l 详解
    PKU2418_树种统计(map应用||Trie树)
  • 原文地址:https://www.cnblogs.com/tiger8000/p/2488834.html
Copyright © 2011-2022 走看看