关闭

asp.net +C# +sql2000 实现仿csdn的图片轮换代码

704人阅读 评论(0) 收藏 举报
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="PicAdrotator.ascx.cs" Inherits="WebJTJ.Control.PicAdrotator" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
        
<div align="center">
            
<script type="text/javascript">


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


var pics
=<%=pics%>;
var links
=<%=links%>;
var texts
=<%=texts%>;

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="wmode" value="transparent"><param name="movie" value="pixviewer.swf"><param name="quality" value="high"><param name="bgcolor" value=#ffffff>');
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+'&textheight='+text_height+'" menu="false" bgcolor=#ffffff 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>
        
</div>

cs 页面代码如下:
    public string pics="''";
        
public string links="''";
        
public string texts="''";
        
public string sqlstr;
        
public string ml;
        
        
private void Page_Load(object sender, System.EventArgs e)
        
{
                SqlConnection conn2
=new SqlConnection();
            
string strConn="server=192.168.1.5;database=WebJTJDB;User Id=sa;pwd=;" ;                
            conn2.ConnectionString
=strConn;
            conn2.Open();
            sqlstr
="select top 4 * from T_WebNews_Content order by NewsID desc";
            SqlCommand cmd
=new SqlCommand(sqlstr,conn2);
            SqlDataReader re
=cmd.ExecuteReader();
            
            ml
="http://"+Request.ServerVariables["HTTP_HOST"].ToString()+"/WebJTJ/webmanage";
            
//ml="webmanage";
            if (re.Read())
            
{

                pics
="'"+ml+"/"+re["picid"+ "'";
                links
="'"+"detail.aspx?aid="+re["newsid"]+"'";
                texts
="'"+CutString(re["title"].ToString(),14)+"'";
            }

            
while (re.Read())
            
{

                pics
=pics+"+'|'+'"+ml+"/"+re["picid"]+"'"
                links
=links+"+'|'+'"+"detail.aspx?aid="+re["newsid"]+"'";
                texts
=texts+"+'|'+'"+ CutString(re["title"].ToString(),14)+"'";    
            }

               


        }

        
public string CutString(string str,int length)
        
{
            
int i = 0, j = 0;
            
foreach(char chr in str)
            
{
                
if((int)chr > 127)
                
{
                    i 
+= 2;
                }

                
else
                
{
                    i 
++;
                }

                
if (i > length)
                
{
                    str 
= str.Substring(0, j) + "";
                    
break;
                }

                j 
++;
            }

            
return str;
        }
 
 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:505561次
    • 积分:5836
    • 等级:
    • 排名:第4560名
    • 原创:21篇
    • 转载:261篇
    • 译文:1篇
    • 评论:90条
    最新评论