asp.net 操作滚动图片新闻
各位大虾:小弟要用asp.net实现一个新闻向右滚动功能,这些滚动新闻都来自于我的后台数据库,
点击图片时链接到相应在地址
。跪求代码,一定加分!十分紧急,谢谢各位大虾了 --------------------编程问答-------------------- Marquee 就可以实现滚动 --------------------编程问答-------------------- 有具体点的代码吗?
--------------------编程问答-------------------- 这里高手这么多也太让我失望了啊
--------------------编程问答-------------------- <Marquee ...>
<%=Content%>
</Marquee>
protect string Content;
Content = ds.Tables[0].Rows[0][0].ToString();
还要给你写链接数据源之类的东东吗 ? --------------------编程问答-------------------- 谢谢了 --------------------编程问答-------------------- <table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<div id="demo" style="overflow: hidden; height: 120; width: 1024; color: #ffffff">
<table align="center" cellpadding="0" cellspace="0" border="0">
<tr>
<td id="demo1" valign="top">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<a href="http://www.163.com" target="_blank">
<img src="../img/图片/1.jpg" width="150" height="100" alt="连接网易看新闻" class="b5" hspace="22"></a><br>
<center>
<a href="http://www.163.com">网易</a>
</center>
</td>
<td width="30">
</td>
<td>
<a href="http://www.baidu.com" target="_blank">
<img src="../img/图片/2.jpg" width="150" height="100" alt="点击连接“百度”" class="b5" hspace="22"></a><br>
<center>
<a href="http://www.baidu.com">百度</a>
</center>
</td>
<td width="30">
</td>
<td>
<a href="#" target="_blank">
<img src="../img/图片/3.jpg" width="150" height="100" class="b5" hspace="22"></a><br>
<center>
<b>说明三</b></center>
</td>
<td>
<a href="#" target="_blank">
<img src="../img/图片/4.jpg" width="150" height="100" class="b5" hspace="22"></a><br>
<center>
<b>说明四</b></center>
</td>
<td width="30">
</td>
<td>
<a href="#" target="_blank">
<img src="../img/图片/5.jpg" width="150" height="100" class="b5" hspace="22"></a><br>
<center>
<b>说明五</b></center>
</td>
<td>
<a href="http://www.163.com" target="_blank">
<img src="../img/图片/1.jpg" width="150" height="100" class="b5" hspace="22"></a><br>
<center>
<b>网易</b></center>
</td>
<td width="30">
</td>
<td>
<a href="http://www.baidu.com" target="_blank">
<img src="../img/图片/2.jpg" width="150" height="100" class="b5" hspace="22"></a><br>
<center>
<b>百度</b></center>
</td>
<td width="30">
</td>
<td>
<a href="#" target="_blank">
<img src="../img/图片/3.jpg" width="150" height="100" class="b5" hspace="22"></a><br>
<center>
<b>说明三</b></center>
</td>
<td>
<a href="#" target="_blank">
<img src="../img/图片/4.jpg" width="150" height="100" class="b5" hspace="22"></a><br>
<center>
<b>说明四</b></center>
</td>
<td width="30">
</td>
<td>
<a href="#" target="_blank">
<img src="../img/图片/5.jpg" width="150" height="100" class="b5" hspace="22"></a><br>
<center>
<b>说明五</b></center>
</td>
</tr>
</table>
</td>
<td id="demo2" valign="top">
</td>
</tr>
</table>
<script>
var speed=4 //速度数值越大速度越慢
demo2.innerHTML=demo1.innerHTML
function Marquee()
{
if(demo2.offsetWidth-demo.scrollLeft<=0)
{
demo.scrollLeft-=demo1.offsetWidth
}
else{
demo.scrollLeft++
}
}
var MyMar=setInterval(Marquee,speed)
demo.onmouseover=function() //处理鼠标悬挺 停止 和 移走后 的重新滚动
{
clearInterval(MyMar)
}
demo.onmouseout=function()
{
MyMar=setInterval(Marquee,speed)
}
</script>
</div>
</td>
</tr>
</table>
你可以试试这个 --------------------编程问答-------------------- Berry_tian
你的方法运行不了... --------------------编程问答-------------------- 看看 --------------------编程问答-------------------- 用<Marquee ...>
</Marquee> 就行了 --------------------编程问答-------------------- <%@ Control Language="C#" AutoEventWireup="true" CodeFile="News.ascx.cs" Inherits="UserAscx_News" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td valign="top">
<asp:Image ID="imgNews" runat="server" Height="120px" Width="160px" />
<cc1:SlideShowExtender ID="SlideShowExtender1" runat="server" TargetControlID="imgNews"
AutoPlay="true" Enabled="true" Loop="true" SlideShowServicePath="NewPictures.asmx"
SlideShowServiceMethod="GetSlides">
</cc1:SlideShowExtender>
</td>
<td valign="top">
<asp:DataList ID="dlNews" runat="server" OnItemDataBound="dlNews_ItemDataBound">
<ItemTemplate>
<asp:HyperLink ID="hlNews" runat="server" Target="_blank"></asp:HyperLink>
</ItemTemplate>
<AlternatingItemStyle CssClass="tr2" Font-Size="12px" HorizontalAlign="Left" />
<ItemStyle CssClass="tr1" Font-Size="12px" HorizontalAlign="Left" />
</asp:DataList>
<asp:HyperLink ID="hlMore" runat="server" Font-Size="12px" Target="_blank">更多新闻...</asp:HyperLink></td>
</tr>
<tr>
<td colspan="2" valign="top">
<asp:Panel runat="server" ID="plScroll" BackColor="white">
<marquee direction="left" id="mq" name="mq" scrollamount="5" behavior="scroll" scrolldelay='100'><asp:Repeater id="rpNews" runat="server" OnItemDataBound="rpNews_ItemDataBound">
<ItemTemplate>
<nowrap>
<asp:HyperLink ID="hlView" runat="server" Target="_blank" Font-Size="12px">[hlView]</asp:HyperLink>
</nowrap>
</ItemTemplate>
</asp:Repeater></marquee>
</asp:Panel>
</td>
</tr>
</table>
--------------------编程问答-------------------- 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 HangBiao.AOA.GongGao;
using Microsoft.Practices.EnterpriseLibrary.Data;
public partial class UserAscx_News : System.Web.UI.UserControl
{
Database db = DatabaseFactory.CreateDatabase("HangBiao");
public readonly int PIC_WIDTH = 160;
public readonly int PIC_HEIGHT = 120;
private int _showCount;
/// <summary>
/// 用户控件中显示的新闻条数
/// </summary>
public int ShowCount
{
get { return _showCount; }
set { _showCount = value; }
}
private int _width;
/// <summary>
/// 控件宽度
/// </summary>
public int Width
{
get { return _width; }
set { _width = value; }
}
private string _moreLinkAddress;
/// <summary>
/// 更多新闻链接
/// </summary>
public string MoreLinkAddress
{
get { return _moreLinkAddress; }
set { _moreLinkAddress = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Page_PreRender(object sender, EventArgs e)
{
imgNews.Height = PIC_HEIGHT;
imgNews.Width = PIC_WIDTH;
if (Width > PIC_WIDTH)
{
dlNews.Width = Width - PIC_WIDTH;
}
plScroll.Width = Width;
DataTable dt = GongGao.GetLatestAnnounce(ShowCount, "图片新闻", db);
dlNews.DataSource = dt;
dlNews.DataBind();
DataTable dt2 = GongGao.GetLatestAnnounce(10, "图片新闻", db);
rpNews.DataSource = dt2;
rpNews.DataBind();
hlMore.NavigateUrl = MoreLinkAddress;
ArrayList alPic = new ArrayList();
foreach (DataRow row in dt.Rows)
{
alPic.Add(row[GongGao.配图].ToString());
}
ViewState["piclist"] = alPic;
imgNews.ImageUrl = alPic[0].ToString();
}
protected void dlNews_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
DataRowView row = e.Item.DataItem as DataRowView;
HyperLink hlNews = e.Item.FindControl("hlNews") as HyperLink;
hlNews.Text = row[GongGao.标题].ToString() + "(" + DateTime.Parse(row[GongGao.添加日期].ToString()).ToShortDateString() + ")";
hlNews.NavigateUrl = "~/AOA/GongGao/GongGao_View.aspx?ID=" + row["ID"].ToString();
}
}
protected void rpNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
DataRowView row = e.Item.DataItem as DataRowView;
HyperLink hlView = e.Item.FindControl("hlView") as HyperLink;
hlView.Text = row[GongGao.标题].ToString() + "(" + DateTime.Parse(row[GongGao.添加日期].ToString()).ToShortDateString() + ")";
hlView.NavigateUrl = "~/AOA/GongGao/GongGao_View.aspx?ID=" + row["ID"].ToString();
}
}
}
--------------------编程问答-------------------- 经过测试。
<form id="Form3" method="post" runat="server">
<FONT face="宋体"></FONT>
<TABLE id="Table1" style="WIDTH: 800px; HEIGHT: 136px" cellSpacing="0" cellPadding="0"
border="0">
<TR>
<TD>
<div id="demo" style="OVERFLOW: hidden; WIDTH: 1000px; HEIGHT: 125px" align="center"
DESIGNTIMEDRAGDROP="134">
<TABLE style="WIDTH: 725px; HEIGHT: 96px">
<TR>
<TD id="demo1" vAlign="middle"><asp:datalist id="DataList1" runat="server" Width="712px" RepeatDirection="Horizontal">
<ItemTemplate>
<FONT face="宋体">
<TABLE id="Table2" style="WIDTH: 102px; HEIGHT: 100px" cellSpacing="0" cellPadding="0"
width="102" border="0">
<TR>
<TD><IMG style="WIDTH: 98px; HEIGHT: 95px" height=95 alt=产品照片 src='<%# DataBinder.Eval(Container.DataItem,"Pimg","upimg\\{0}")%>' width=98 border=0></TD>
</TR>
<TR>
<TD align="center"><A href='Productinfo.aspx?Pid=<%#DataBinder.Eval(Container.DataItem,"id")%>' target=_blank><%# DataBinder.Eval(Container.DataItem,"Pname")%></A></TD>
</TR>
</TABLE>
</FONT>
</ItemTemplate>
<AlternatingItemTemplate>
<TABLE id="Table4" style="WIDTH: 102px; HEIGHT: 117px" cellSpacing="0" cellPadding="0"
width="102" border="0">
<TR>
<TD><IMG style="WIDTH: 98px; HEIGHT: 95px" height=95 alt=产品照片 src='<%# DataBinder.Eval(Container.DataItem,"Pimg","upimg\\{0}")%>' width=98 border=0></TD>
</TR>
<TR>
<TD align="center"><A href='Productinfo.aspx?Pid=<%#DataBinder.Eval(Container.DataItem,"id")%>' target=_blank><%# DataBinder.Eval(Container.DataItem,"Pname")%></A></TD>
</TR>
</TABLE>
</AlternatingItemTemplate>
</asp:datalist></TD>
<TD id="demo2" vAlign="top"><FONT face="宋体"></FONT></TD>
</TR>
</TABLE>
</div>
</TD>
</TR>
</TABLE>
<script>
var Picspeed=30
demo2.innerHTML=demo1.innerHTML
function Marquee1(){
if(demo2.offsetWidth-demo.scrollLeft<=0)
demo.scrollLeft-=demo1.offsetWidth
else{
demo.scrollLeft++
}
}
var MyMar1=setInterval(Marquee1,Picspeed)
demo.onmouseover=function() {clearInterval(MyMar1)}
demo.onmouseout=function() {MyMar1=setInterval(Marquee1,Picspeed)}
</script>
</form>
--------------------编程问答-------------------- 太难为上面这些贴codes的大侠了 --------------------编程问答-------------------- HOHO --------------------编程问答-------------------- 喔 --------------------编程问答-------------------- 太感谢xierfly了,你的代码行!!!!!!!!!!!!! --------------------编程问答-------------------- 来晚了都解决了啊。JF吧 --------------------编程问答-------------------- --------------------编程问答-------------------- BU CUO !
--------------------编程问答-------------------- mark --------------------编程问答-------------------- 想不想要一些特效? --------------------编程问答-------------------- d --------------------编程问答-------------------- <%# DataBinder.Eval(Container.DataItem,"Pimg","upimg\\{0}")%>
"upimg\\{0}" 是什么意思?
谢谢 --------------------编程问答-------------------- <Marquee ...> 网上查用法。。还是很简单的。。 --------------------编程问答-------------------- 6#的可以 --------------------编程问答-------------------- 学习了 这里高手如云啊 --------------------编程问答-------------------- 你家 asp.net 中有Marquee 标签 --------------------编程问答-------------------- 支持marquee、、 --------------------编程问答-------------------- 长见识了 --------------------编程问答-------------------- 学习了 --------------------编程问答-------------------- 来学习一下~!!! --------------------编程问答-------------------- 有不用marquee标签实现的吗? 在asp。net页面里没有自带的marquee标签啊 --------------------编程问答-------------------- <Marquee ...>
内容
</Marquee>
</Marquee> 是标签 --------------------编程问答-------------------- 用了上面高手的代码 图片不会滚动。 是怎么回事啊 --------------------编程问答-------------------- 用<Marquee ...>的话 图片不会循环滚动的
所以能不能提供一个让图片循环滚动的方法??
--------------------编程问答-------------------- 后台读完数据 造html代码输出到前台 --------------------编程问答-------------------- 你们好!我也是学软件开发学生,今年大三了,我还是第一次在这里问问题,以前都是从里面搜出来的,我想想做这个样式的分页滚动新闻,各位大侠能帮我回答一下吗[img=http://C:\Documents and Settings\Administrator\桌面][/img] --------------------编程问答-------------------- 懒人图库里有 jquery插件。我一直用这个,感觉不错 你看看
http://www.lanrentuku.com/js/jiaodiantu-794.html --------------------编程问答-------------------- 将数据绑定到<marquee></marquee>之间
补充:.NET技术 , ASP.NET