当前位置:编程学习 > C#/ASP.NET >>

在asp.net

这个用在asp.net中怎么实现的啊,图片名从数据库中调出来。怎么写页面和Cs文件的代码 下面有一段代码是用jsp做的。怎么改成asp.net(c#)的页面能用的啊

<%
function g(t)
if len(t)>12 then
g=left(t,12)&"…"
else
g=t
end if
end function

pic=""
link=""
imgtext=""

sql="select top 5 * from zm_news where img<>'' order by id desc"
Set rs=conn.execute(sql)
do while not rs.eof
pic=pic&"|"&rs("img")
link=link&"|"&"news_view.asp?id="&rs("id")
imgtext=imgtext&"|"&g(rs("title"))
rs.MoveNext
loop
rs.Close
set rs=nothing


pic=right(pic,len(pic)-1)
link=right(link,len(link)-1)
imgtext=right(imgtext,len(imgtext)-1)
%>
<a target="_blank" href="javascript:goUrl()">
<span class="f14b">
<script type="text/javascript">

var focus_width=200
var focus_height=140
var text_height=20
var swf_height = focus_height+text_height

var pics="<%=pic%>"
var links="<%=link%>"
var texts="<%=imgtext%>"

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="playswf.swf"><param name=wmode value=transparent><param name="quality" value="high">');
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="playswf.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#DADADA" 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>
</span></a><span id="focustext" class="f14b"> </span>
<body>
</body>
</html>

追问:var pics = "<%=pic%>";
var links = "<%=link%>";
var texts = "<%=imgtext%>";编译不能通过

我改成这样

var pics = '<%# Eval("pic")%>';
var links ='<%# Eval("link")%>';
var texts ='<%# Eval("imgtext")%>';

也不行啊,

我后台是这样的啊

using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
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 hzml.Bll;
using hzml.Models;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CompanyManager companyManager=new CompanyManager();
CompanyPic companyPic=null;
string pic="";
string link="";
string imgtext="";
List<CompanyPic> list=companyManager.GetlistCompanyPic();
for(int i=0;i<list.Count;i++)
{
companyPic=list[i];
pic +="|"+companyPic.CompanyName;
link +="|"+"Default.asp?id="+companyPic.Id;
imgtext +="|"+g(companyPic.CompanyNumber.ToString());
}
pic=pic.TrimStart('|');
link=link.TrimStart('|');
imgtext=link.TrimStart('|');
}
private string g(string t)
{
if(t.Length > 12)
{
return t.Substring(0, 12) + "...";
}
return t;
}

}

答案:不知道你这个数据库的结构是不是和你举的例子一样,还有一些别的细节之类的,我都不清楚,只能跟你说的是这个使用了个flash,有参数的,参数应该就是图片地址之类的,我把这个asp翻译了一下,你自己研究吧

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication7.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<a target="_blank" href=> <script type="text/javascript">
var focus_width = 200;
var focus_height = 140;
var text_height = 20;
var swf_height = focus_height + text_height;

var pics = "<%=pic%>";
var links = "<%=link%>";
var texts = "<%=imgtext%>";

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="playswf.swf"><param name=wmode value=transparent><param name="quality" value="high">');
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="playswf.swf" wmode="opaque" FlashVars="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '" menu="false" bgcolor="#DADADA" 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>
</span></a><span id="focustext" class="f14b"></span>
</div>
</form>
</body>
</html>

cs文件

using System;
using System.Data.SqlClient;

namespace WebApplication7
{
public partial class WebForm2 : System.Web.UI.Page
{
protected string pic = string.Empty;
protected string link = string.Empty;
protected string imgtext = string.Empty;

private string g(string t)
{
if(t.Length > 12)
{
return t.Substring(0, 12) + "...";
}

return t;
}

protected void Page_Load(object sender, EventArgs e)
{
string sql = "select top 5 * from zm_news where img<>'' order by id desc";
SqlConnection conn = new SqlConnection("你的ConnectionString");
SqlCommand cmd = new SqlCommand(sql, conn);

conn.Open();

SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

while (reader.Read())
{
pic += "|" + reader["img"];
link += "|" + "news_view.asp?id=" + reader["id"];
imgtext += "|" + g(reader["title"].ToString());
}

reader.Close();

pic = pic.TrimStart('|');
link = link.TrimStart('|');
imgtext = imgtext.TrimStart('|');
}
}
}

因为不知道是什么库,暂时写了个sqlserver库的,你看着研究吧。

<a target=_self href=><span class="f14b">
<script type="text/javascript">
imgUrl1="<%=imgUrl1%>";
imgtext1="<%=imgtext1%>";
imgLink1=escape("<%=imgLink1%>");
imgUrl2="<%=imgUrl2%>";
imgtext2="<%=imgtext2%>";
imgLink2=escape("<%=imgLink2%>");
imgUrl3="<%=imgUrl3%>";
imgtext3="<%=imgtext3%>"
imgLink3=escape("<%=imgLink3%>");
imgUrl4="<%=imgUrl4%>";
imgtext4="<%=imgtext4%>";
imgLink4=escape("<%=imgLink4%>");
imgUrl5="<%=imgUrl5%>";
imgtext5="<%=imgtext5%>";
imgLink5=escape("<%=imgLink5%>");

var focus_width=360
var focus_height=210
var text_height=25
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=" http://www.webjx.com/js/focus.swf">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="pixviewer.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height-2+'&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>

上一个:asp.net脚本
下一个:关于asp.net

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,