实现从数据库中读取图片或flash的链接,然后在网页中显示图片或flash。我们首先需要分析一下链接的格式,然后判断是图片链接还是flash的链接,这个就需要判断链接的后缀名了。
//声明存储网页图片或flash字符串的变量
public string top_mainPICorFlash;
//绑定首页图片或者flash
OleDbDataAdapter selectpicurl = new OleDbDataAdapter("select Purl from picflash where Ptype=''index'' order by Pid DESC",conn);
DataSet selectpicds = new DataSet();
selectpicurl.Fill(selectpicds);
//图片或flash的url地址
string flashpicurl = selectpicds.Tables[0].Rows[0][0].ToString();
//获取url的后缀名
string houzhui = flashpicurl.Substring(flashpicurl.LastIndexOf(".")+1,flashpicurl.Length-flashpicurl.LastIndexOf(".")-1);
//判断后缀名格式,并给存储网页图片或flash字符串的变量赋值
//注意防止转义的@符号以及双引号里面的单引号,字符串中的变量我用蓝色标注
if(houzhui=="jpg"||houzhui=="gif"||houzhui=="png"||houzhui=="jpeg")
{
top_mainPICorFlash = @"<img src=''"+flashpicurl+"'' width=''820'' height=''280'' />";
}
else if(houzhui=="swf")
{
top_mainPICorFlash = @"<object classid=''clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'' codebase=''http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0''
width=''820'' height=''280'' VIEWASTEXT><param name=''movie'' value=''"+flashpicurl+@"'' /><param name=''quality'' value=''high'' /><embed src=''"+flashpicurl+@"''quality=''high'' pluginspage=''http://www.macromedia.com/go/getflashplayer'' type=''application/x-shockwave-flash'' width=''820'' height=''280''></embed></object>";
}
HTML中这样写
<%=top_mainPICorFlash%> //注意是=号,不是习惯的#号
当然,安装这个你完全可以自己作一个广告系统了,呵呵.
|