首页 > 开发 > 综合 > 正文

Simple Image Slide Show C# edition

2024-07-21 02:18:52
字体:
来源:转载
供稿:网友

最大的网站源码资源下载站,

simple image slide show c# edition

by hehong yang(杨贺宏)

in scott mitchell’s article, he create a simple image slide show using asp.net with vb.net. now i rewrite it in c#. i create a sub directory photos to store the image files. and instead of using datalist control, i used dropdownlist control to list all image files. i use it in my personal web site, so you can view a live demo there( http://www17.brinkster.com/flycrane/album/default.aspx ).

soure code: default.aspx

<%@ page language="c#" %>

<%@ import namespace="system.io" %>

<script runat="server">

// insert page code here

private void page_load(object sender, system.eventargs e)

{

//get list of images

directoryinfo dirinfo= new directoryinfo( server.mappath("photos"));

fileinfo[] images= imagesfilter( dirinfo.getfiles() );

//determine the current image to show

int imageindex= 0;

if( request.querystring["n"]!=null )

imageindex= convert.toint32( request.querystring["n"] );

lbltitle.text+= path.getfilenamewithoutextension( images[imageindex].name )

+" ("+ (imageindex+1) +" of "+images.length+")";

currentimage.imageurl= "/flycrane/album/photos/"+images[imageindex].name ;

if( imageindex>0 )

lnkprev.navigateurl= "default.aspx?n=" + (imageindex - 1);

if( imageindex<images.length-1 )

lnknext.navigateurl= "default.aspx?n=" + (imageindex +1);

if(! ispostback)

{

ddlimages.datasource= images;

ddlimages.databind();

}





}

public fileinfo[] imagesfilter( fileinfo[] files )

{

arraylist newimages= new arraylist( files.length );

for( int i=0;i<files.length;i++ )

{

if( path.getextension( files[i].name.tolower() )==".jpg" ||

path.getextension( files[i].name.tolower() )==".jpeg" ||

path.getextension( files[i].name.tolower() )==".png" ||

path.getextension( files[i].name.tolower() )==".gif"

)

newimages.add(files[i]);

}

return ( fileinfo[] ) newimages.toarray( files[0].gettype() );

}

void ddlimages_selectedindexchanged(object sender, eventargs e) {

response.redirect( "default.aspx?n="+ (ddlimages.selectedindex) );

}

</script>

<html>

<head>

<title>flycrane's personal web site</title>

<link rel="stylesheet" src="/flycrane/styles/flycrane.css" />

</head>

<body>

<form runat="server">

<table cellspacing="0" cellpadding="0" width="765" align="center" border="0">

<!--dwlayouttable-->

<tbody>

<tr>

<td align="middle" width="765" bgcolor="#9999cc">

<asp:label id="lbltitle" runat="server" width="206px">you are viewing: </asp:label></td>

</tr>

<tr>

<td align="middle" width="765">

<p>

<asp:image id="currentimage" runat="server"></asp:image>

</p>

</td>

</tr>

<tr>

<td align="middle" width="765" bgcolor="#9999cc">

<asp:hyperlink id="lnkprev" runat="server">previous</asp:hyperlink>

&nbsp;<asp:hyperlink id="lnknext" runat="server">next</asp:hyperlink>

</td>

</tr>

<tr>

<td align="middle" width="765" bgcolor="#9999cc">

select one photo:

<asp:dropdownlist id="ddlimages" runat="server" onselectedindexchanged="ddlimages_selectedindexchanged" autopostback="true"></asp:dropdownlist>

</td>

</tr>

</tbody>

</table>

</form>

</body>

</html>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表