我在页面添加了一个滚动新闻栏,怎样使其每天显示最新新闻 ( 积分: 100 )

  • 主题发起人 灿烂的阳光(二)
  • 开始时间

灿烂的阳光(二)

Unregistered / Unconfirmed
GUEST, unregistred user!
我在页面上添加了一个滚动的新闻栏,怎样使其每天自动显示最新新闻(在数据库调出最新新闻我会,但是怎样动态改变链接的字样我不会),代码如下:
<MARQUEE
style=&quot;WIDTH: 406px;
HEIGHT: 9px&quot;
onmouseout=&quot;this.start()&quot;
onmouseover=&quot;this.stop()&quot;
scrollAmount=&quot;2&quot;
direction=&quot;left&quot;
behavior=&quot;scroll&quot;
width=&quot;406&quot;
height=&quot;9&quot;>
<A href=&quot;http://localhost/newsdisplay?ID=新闻的ID&quot;>链接字样</A></MARQUEE>
也就是怎样动态改变代码中的新闻ID 和 链接字样
 
你可以使用遍历数据集的方法,动态的构造<A>标记
 
string hc=Convert.ToString((Char)13) ;
string sql=&quot;&quot;;
string mr=&quot;<marquee direction='up' onMouseOver='javascript:this.stop();' onmouseout='javascript:this.start();' scrollamount='3'>&quot;;
string zx=&quot;&quot;;
OleDbConnection Olecn=new OleDbConnection(Session[&quot;constr&quot;].ToString());
Olecn.Open();
sql=&quot;select top 30 id,left(zxbt,10)+zxnew as bt from zxzxb order by id desc&quot;;
OleDbCommand cm=new OleDbCommand(sql,Olecn);
OleDbDataReader dr;
dr=cm.ExecuteReader();
int i=0;
string a=@&quot;&quot;;
while(dr.Read())
{
zx+=&quot;<a href='#' onclick=&quot;+a+&quot;window.open('shggl_1.aspx?id=&quot;+dr[&quot;id&quot;].ToString()+&quot;','','toolbar=no,menubar=no,scrollbars=yes,resizable=yes,status=no,location=no,directories=no,copyhistory=no,height=450,width=580,left=100,top=100')&quot;+a+&quot;>&quot;+dr[&quot;bt&quot;]+&quot;</a><br><br>&quot;;
i+=1;
}
dr.Close();
Olecn.Close();
zx=mr+zx+&quot;<a href='ggl.aspx'>·更多公告...</a></marquee>&quot;;
 
石嶷山友,我想问一下:这段代码是写在后台(即:aspx.cs中),还是在页面中(<%写在这里%>。
还有这段代码里哪几句体现出来往页面上布置滚动信息了,我怎么没发现,zx只是个字符串,它并没有布置啊?小弟是个初学者,没有什么经验,请多多指点一下,谢谢了
 
放一个 Label 控件在你所需要的位置上,在以上的代码后面加一行:
Label1.Text=zx;
即可了。
 
顶部