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>
[解决办法]
前台放个Litral控件 后台从数据库取到数据后拼成html,然后给定Litral控件的text属性 这样行不
[解决办法]
- C# code
客户端代码:<script type="text/javascript"> var focus_width=300 //图片宽度 var focus_height=225 //图片高度 var text_height=25 //文本标题高度 var swf_height = focus_height+text_height var pics="<%=pics%>" var links="<%=links%>" var texts="<%=texts%>" pics=pics.substring(0,pics.length-1); links=links.substring(0,links.length-1); texts=texts.substring(0,texts.length-1); 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 +'" align="left" hspace="10">'); document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="artical/pixviewer.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('<embed src="artical/pixviewer.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#F0F0F0" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'); document.write('</object>'); </script>服务器端代码:SqlDataReader re = (SqlDataReader)FcadeHelper.GetDataHelper).ExecuteReader("select top 6 * from tblArtic"); while (re.Read()) { pics += re["pic"].ToString() + "|"; links += "detail.aspx?aid=" + re["id"].ToString() + "|"; texts += re["topic"].ToString() + "|"; }
[解决办法]
图片轮换,一般都有后台管理图片的地方。
因为到程序发布以后,也不能叫用户去操作数据库。
所以我倒是建议你,做一个管理图片的部分。
[解决办法]
楼主,说的,这情况我上次做了一个轮播的图片,代码发给你- C# code
<script type="text/javascript"> var GB_ROOT_DIR = "./greybox/"; </script> <script type="text/javascript" src="greybox/AJS.js"></script> <script type="text/javascript" src="greybox/AJS_fx.js"></script> <script type="text/javascript" src="greybox/gb_scripts.js"></script> <link href="greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" /> <script language="javascript" type="text/javascript">var s=function(){var interv=5000; //л?var interv2=10; //лvar opac1=80; //??var source="fade_focus" //???id//?function getTag(tag,obj){if(obj==null){return document.getElementsByTagName(tag)}else{return obj.getElementsByTagName(tag)}}function getid(id){return document.getElementById(id)};var opac=0,j=0,t=63,num,scton=0,timer,timer2,timer3;var id=getid(source);id.removeChild(getTag("div",id)[0]);var li=getTag("li",id);var div=document.createElement("div");var title=document.createElement("div");var span=document.createElement("span");var button=document.createElement("div");button.className="button";for(var i=0;i<li.length;i++){var a=document.createElement("a");a.innerHTML=i+1;a.onclick=function(){clearTimeout(timer);clearTimeout(timer2);clearTimeout(timer3);j=parseInt(this.innerHTML)-1;scton=0;t=63;opac=0;fadeon();};a.className="b1";a.onmouseover=function(){this.className="b2"};a.onmouseout=function(){this.className="b1";sc(j)};button.appendChild(a);}//??function alpha(obj,n){if(document.all){obj.style.filter="alpha(opacity="+n+")";}else{obj.style.opacity=(n/100);}}//???function sc(n){for(var i=0;i<li.length;i++){button.childNodes[i].className="b1"};button.childNodes[n].className="b2";}title.className="num_list";title.appendChild(span);alpha(title,opac1);id.className="d1";div.className="d2";id.appendChild(div);id.appendChild(title);id.appendChild(button);//var fadeon=function(){opac+=5;div.innerHTML=li[j].innerHTML;span.innerHTML=getTag("img",li[j])[0].alt;alpha(div,opac);if(scton==0){sc(j);num=-2;scrolltxt();scton=1};if(opac<100){timer=setTimeout(fadeon,interv2)}else{timer2=setTimeout(fadeout,interv);};}//var fadeout=function(){opac-=5;div.innerHTML=li[j].innerHTML;alpha(div,opac);if(scton==0){num=2;scrolltxt();scton=1};if(opac>0){timer=setTimeout(fadeout,interv2)}else{if(j<li.length-1){j++}else{j=0};fadeon()};}//var scrolltxt=function(){t+=num;span.style.marginTop=t+"px";if(num<0 && t>3){timer3=setTimeout(scrolltxt,interv2)}else if(num>0 && t<62){timer3=setTimeout(scrolltxt,interv2)}else{scton=0}};fadeon();}//?window.onload=s;</script>上面是JS代码,下面是在调用的,图片是从数据库中读取出来的,我把读取图片的代码写在homephoto自定义控件中,<div id="fade_focus"> <div class="loading"></div> <cm:homephoto ID="homephoto" runat="server" /></div>自定义控件代码<script runat="server"> private void Page_Load(Object source, EventArgs e) { if (!Page.IsPostBack) { CMSettingphotoCollection cmPhoto=new CMSettingphotoCollection(); cmPhoto.ListAll(); rpPhoto.DataSource = cmPhoto.List; rpPhoto.DataBind(); } }</script><asp:repeater id="rpPhoto" runat="server" ><itemtemplate><ul class="ul_1"><li><a href='<%# ((CMSettingphoto) Container.DataItem).SPGurl %>' target="_blank"><img src="<%# CMSite.RetrieveUrl() + "/" + CMSite.RetrieveResourceRef() + "/"+((CMSettingphoto) Container.DataItem).Experience %>" /></a></li> </ul></itemtemplate></asp:repeater>
[解决办法]
不管怎么切换,后台的数据最终到页面上还是html内容。
[解决办法]
兄弟 我看你还真是新手
这种静态JS的可以随便换成后台改变的啊
imgUrl1="images/001.jpg";
imgtext1="走进鄂尔多斯草原 感受自然美景"
imgLink1=escape("http://www.shizhenyuan.com");
你本来是这样的对吧
你以后看到这种JS的 不管是JS 还是 HTML
在asp.net中都可以用到<%=pic1%>这种赋值方式
比如说
我前台这样得到一个图片值 和一个连接地址
imgUrl1="<%=pic1%>";
imgLink1=escape("<%=url1%>");
在后台代码这样给pic1 和url1变量赋值
public string pic1= string.Empty;
public string url1= string.Empty;
//在Page方法上面定义全局变量
protected void Page_Load(object sender, EventArgs e)
{
//页面初始化时动态赋值
pic1="images/001.jpg";
url1= "http://www.shizhenyuan.com";
}
[解决办法]
像这种换图片的代码 只要别人网站上有 可以随时查看源码复制下来 变成自己的
[解决办法]
如果不想每次都手动更换图片,那就把这些图片保存在数据库中就可以,
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");
当然为了好看,结构清晰:
一共分为三段 imgURL imgName linkUrl 可以保存在一个XML或者一个JSOIN 中,当然不管是JOIN还是XML 肯定是表中某一个字段的值,到时候读取这个字符串转换成XML格式解析循环在后台通过timer也可以调用,当然JS也可以,不过最好是用JS 嘿嘿。
[解决办法]
操作XML文件bcastr.xml
JQUERY切换图片
http://topic.csdn.net/u/20091111/01/6eb7f062-3825-4af0-bce2-4ce82035c822.html
[解决办法]
看我的,
- C# code
幻灯片绑定数据库<script type="text/javascript">var focus_width=246var focus_height=180var text_height=20var swf_height = focus_height+text_heightvar pics='<%=H1%>' var links='<%=H2%>'var texts='<%=H3%>'document.write('<object ID="focus_flash" 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="js/hdp.swf"><param name="quality" value="high"><param name="bgcolor" value="#FFFFFF">');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('<embed ID="focus_flash" src="js/hdp.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#FFFFFF" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'); document.write('</object>');</script>public string H1,H2,H3;private void hdp() { string aa=""; string bb=""; string cc=""; SqlConnection MyConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connectionString"]); string strSelect="select top 5 * from xinwen where x_lx='幻灯片新闻' ORDER BY px asc,x_time DESC"; SqlCommand myCommand=new SqlCommand(strSelect,MyConnection); MyConnection.Open(); SqlDataReader sdr = myCommand.ExecuteReader(); while(sdr.Read()) { aa += sdr["x_images"].ToString()+"|"; bb += sdr["x_id"].ToString()+".html|"; cc += sdr["x_name"].ToString()+"|"; H1=aa.Substring(0,aa.LastIndexOf("|")); H2=bb.Substring(0,bb.LastIndexOf("|")); H3=cc.Substring(0,cc.LastIndexOf("|")); } sdr.Close(); MyConnection.Close(); }
[解决办法]
http://blog.csdn.net/Teng_s2000/archive/2007/04/25/1584526.aspx