各大网站幻灯片Flash广告的ASP.Net/C#版

找来不少代码,都是用js写的,由于我的平台是基于C#的.net开发的,而且又特别想直接去读取SQL数据库来显示Flash图片新闻,所以就自己写了一个.net版的,各位达人看看,有什么地方可以改进的,给点意见,也给各位用.net开发者的一个思路。

下面贴代码了。

ShowFlashAd.aspx

    <form id="form1" runat="server">
    <div>
         <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"; target=_blank>http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="<%=Pics_Width %>" height="<%=Swf_Height %>"> 
         <param name="allowscriptaccess" value="sameDomain"/> 
         <param name="movie" value="flash/loader.swf"/> 
         <param name="quality" value="high"/>
         <param name="bgcolor" value="#F0F0F0"/> 
         <param name="menu" value="false"/>
         <param name="wmode" value="opaque"/>
         <param name="flashvars" value="Pics=<%=Pics %>&links=<%=Links %>&texts=<%=Texts %>
                    &borderwidth=<%=Pics_Width %>&borderheight=<
                    %=Pics_Height %>&textheight=<%=Texts_Height %>"/>
         </object>                   
     </div>
     </form>

这个主要是用在前台显示Flash的,各位一看就知道了,不过要自己去下载一个loader.swf的文件。

ShowFlashAd.aspx.cs

using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Data.SqlClient; 
public partial class Page_Function_showflashad : System.Web.UI.Page 
{ 
    public int Pics_Width = 240; 
    public int Pics_Height = 180; 
    public int Texts_Height = 18; 
    public int Swf_Height; 
    public string Pics; 
    public string Links; 
    public string Texts; 
    public void Page_Load(object sender, EventArgs e) 
    { 
        //链接数据库,并获取数据库中FlashAD表中的数据 
        SqlConnection objConn = new SqlConnection(); 
        objConn.ConnectionString = ConfigurationManager.ConnectionStrings["yntvuConnectionString"].ConnectionString; 
        objConn.Open(); 
        SqlCommand objCmd = new SqlCommand(); 
        objCmd.Connection = objConn; 
        objCmd.CommandText = "Select Top 6 * From FlashAdPic Where IsShow='1' and IsDel='0'"; 
        SqlDataReader objReader=objCmd.ExecuteReader(); 
        //将查询结果保存到数组变量中,并进行调用 
        string[] imgPics = new string[6]; 
        string[] imgTexts = new string[6]; 
        string[] imgLinks = new string[6]; 
        int i; 
        for (i = 0; i < 6; i++) 
        { 
            objReader.Read(); 
            imgPics = objReader["Pics"].ToString(); 
            imgLinks = objReader["Links"].ToString(); 
            imgTexts = objReader["Texts"].ToString(); 
            Pics = i == 5 ? Pics = Pics + imgPics : Pics + imgPics + "|"; 
            Links = i == 5 ? Links = Links + imgLinks: Links + imgLinks + "|"; 
            Texts = i == 5 ? Texts= Texts + imgTexts: Texts + imgTexts + "|"; 
        } 
        objConn.Close(); 
        Swf_Height = Pics_Height + Texts_Height; 
    } 
} 

这里我只固定显示6幅图,可以自行更改数量,或者修改成动态的也没问题。

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页