这是在你需要展示该功能的页面的html代码:
<td width="40%">
<div align="center">
<iframe width="210" height="190" marginwidth="0" marginheight="0" hspace="0" vspace="0"
frameborder="0" scrolling="no" src="PicsNews.aspx"></iframe>
</div>
</td>
-----------------------------------------------------------------------------------------------------------------------------------------------------
这是PicsNews.aspx的后台代码,只需添加一个标签Labe_pic即可:
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 CB_Article.Web
{
public partial class PicsNews : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string news_pics = string.Empty;
string pics = string.Empty;
string links = string.Empty;
string texts = string.Empty;
//这里尽管是业务层实现的,但是无非//是想要得到一个DataSet
CB_Article.BLL.CB_Articles Artbll = new CB_Article.BLL.CB_Articles();
DataSet ds = Artbll.GetList(" Top 5 [Article_ID],'Article_Title'=Substring(Article_Title,0,10),[FirstImgURL]", " [ImageNum] > 0 ORDER BY [AddTime] DESC");
int Rows = ds.Tables[0].Rows.Count;//这样的写法有助于提高系统性能,因为循环里面就是和常数比较了,省掉了对象构建、销毁以及底层寻址等操作
for (int i = 0; i < Rows; i++)
{
if (i == Rows - 1)
{
pics += ds.Tables[0].Rows[i]["FirstImgURL"].ToString();
links += "RedArt.aspx?id=" + ds.Tables[0].Rows[i]["Article_ID"].ToString();
texts += ds.Tables[0].Rows[i]["Article_Title"].ToString();
}
else
{
pics += ds.Tables[0].Rows[i]["FirstImgURL"].ToString() + "|";
links += "RedArt.aspx?id=" + ds.Tables[0].Rows[i]["Article_ID"].ToString() + "|";
texts += ds.Tables[0].Rows[i]["Article_Title"].ToString() + "|";
}
}
news_pics = "<SCRIPT type=text/javascript>";
news_pics += "var focus_width=210;";
news_pics += "var focus_height=170;";
news_pics += "var text_height=20;";
news_pics += "var swf_height = focus_height+text_height;";
news_pics += "var pics=/"" + pics + "/";";
news_pics += "var links=/"" + links + "/";";
news_pics += "var texts=/"" + texts + "/";";
news_pics += "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 +'/">');";
news_pics += "document.write('<param name=/"allowScriptAccess/" value=/"sameDomain/"><param name=/"movie/" value=/"images/viewer.swf/"><param name=/"quality/" value=/"high/"><param name=/"bgcolor/" value=/"#FFFFFF/">');";
news_pics += "document.write('<param name=/"menu/" value=/"false/"><param name=wmode value=/"opaque/">');";
news_pics += "document.write('<param name=/"FlashVars/" value=/"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'/">');";
news_pics += "document.write('<embed src=/"images/viewer.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=/"'+ focus_height +'/" allowScriptAccess=/"sameDomain/" type=/"application/x-shockwave-flash/" pluginspage=/"http://www.macromedia.com/go/getflashplayer/" />');";
news_pics += "document.write('</object>');";
news_pics += "</SCRIPT>";
Labe_pic.Text = news_pics;
}
}
}