当前位置: 代码迷 >> ASP.NET >> 100分请高手 ASP.net连接数据库怎么实现图片轮换
  详细解决方案

100分请高手 ASP.net连接数据库怎么实现图片轮换

热度:356   发布时间:2013-02-25 00:00:00.0
100分请高手 ASP.net连接数据库如何实现图片轮换
ASP.net连接数据库如何实现图片轮换,就是类似于新浪、搜狐等一些网站新闻图片切换程序,右下角有1,2,3,4.大部分是用js写的,在网上找了一天,大部分程序都是静态显示,如果要更换图片的话只能手工去改,不能实现后台发布新闻图片,前面就能实时切换显示。而有些连接数据库的拿过来改动后就是显示不了图片,哪位高手如能给一份,不甚感激。要求asp.net的,非常感谢,希望能把程序给全,确实能用,今天在线等待!!!  
这份是静态的,能给类似的就行。
<script type="text/javascript">
imgUrl1="images/001.jpg";
imgtext1="走进鄂尔多斯草原 感受自然美景"
imgLink1=escape("http://www.shizhenyuan.com");
imgUrl2="images/002.jpg";
imgtext2="鄂尔多斯遗鸥国家级自然保护区--世珍园旅游区"
imgLink2=escape("http://www.shizhenyuan.com");
imgUrl3="images/003.jpg";
imgtext3="鄂尔多斯遗鸥国家级自然保护区--世珍园旅游"
imgLink3=escape("http://www.shizhenyuan.com");
imgUrl4="images/004.jpg";
imgtext4="碧野茫茫的鄂尔多斯大草原"
imgLink4=escape("http://www.shizhenyuan.com");
imgUrl5="images/005.jpg";
imgtext5="美丽的草原我的家"
imgLink5=escape("http://www.shizhenyuan.com");

 var focus_width=588
 var focus_height=254
 var text_height=18
 var swf_height = focus_height+text_height
 
 var pics=imgUrl1+"|"+imgUrl2+"|"+imgUrl3+"|"+imgUrl4+"|"+imgUrl5 
 var links=imgLink1+"|"+imgLink2+"|"+imgLink3+"|"+imgLink4+"|"+imgLink5
 var texts=imgtext1+"|"+imgtext2+"|"+imgtext3+"|"+imgtext4+"|"+imgtext5
 
 document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
 document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="images/focus2.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">');
 document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
 document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
 document.write('</object>');
</script>

------解决方案--------------------------------------------------------
把这个js弄成静态模板 后台遍历数据替换标签就行了
------解决方案--------------------------------------------------------
C# code
后台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;namespace Vincent.Web.UC{    public partial class falsh : System.Web.UI.UserControl    {        Vincent.Model.Products MInfo = new Vincent.Model.Products();        Vincent.BLL.Products BInfo = new Vincent.BLL.Products();        protected void Page_Load(object sender, EventArgs e)        {        }        #region Web Form Designer generated code        override protected void OnInit(EventArgs e)        {            //            // CODEGEN: This call is required by the ASP.NET Web Form Designer.            //            InitializeComponent();            base.OnInit(e);        }        /**/        /// <summary>        /// Required method for Designer support - do not modify        /// the contents of this method with the code editor.        /// </summary>        private void InitializeComponent()        {            this.Load += new System.EventHandler(this.Page_Load);        }        #endregion        protected string LoadImage()        {            string strWhere = " PClass.PCID=Products.PCID and PClass.PCName='资质荣誉' order by PIndex, PTime desc";            DataSet ds = new DataSet();            ds = BInfo.GetList(strWhere, 4);            string img = "";            img += "var ImgSrc = new Array();";            img += "var ImgAlt = new Array();";            img += "var ImgUrl = new Array();";            for (int m = 0; m < ds.Tables[0].Rows.Count; m++)            {                img += "ImgSrc[" + m + "] = " + "\"" + ds.Tables[0].Rows[m]["PImage"].ToString() + "\";";                img += "ImgAlt[" + m + "] = " + "\"" + ds.Tables[0].Rows[m]["PName"].ToString() + "\";";                img += "ImgUrl[" + m + "] = " + "\"" + ds.Tables[0].Rows[m]["PID"].ToString() + "\";";            }            return img;        }    }}前台<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="falsh.ascx.cs" Inherits="Vincent.Web.UC.falsh" %><a target="_self" href="javascript:goUrl()"><span class="f14b">    <script type="text/javascript">                  <%=LoadImage() %>                                   imgUrl1=ImgSrc[0];imgtext1=ImgAlt[0]imgLink1=escape("zhengshu.aspx?PID="+ImgUrl[0]);imgUrl2=ImgSrc[1];imgtext2=ImgAlt[1]imgLink2=escape("zhengshu.aspx?PID="+ImgUrl[1]);imgUrl3=ImgSrc[2];imgtext3=ImgAlt[2]imgLink3=escape("zhengshu.aspx?PID="+ImgUrl[2]);imgUrl4=ImgSrc[3];imgtext4=ImgAlt[3]imgLink4=escape("zhengshu.aspx?PID="+ImgUrl[3]); var focus_width=185 var focus_height=110 var text_height=0 var swf_height = focus_height+text_height  var pics=imgUrl1+"|"+imgUrl2+"|"+imgUrl3+"|"+imgUrl4 var links=imgLink1+"|"+imgLink2+"|"+imgLink3+"|"+imgLink4  document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">'); document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="../images/focus.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">'); document.write('<param name="menu" value="false"><param name=wmode value="opaque">'); document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">'); document.write('<embed src="../images/focus.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#F0F0F0" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');  document.write('</object>');     </script></span></a>
  相关解决方案