技术来源于同学会实践
前台设计
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="txh.aspx.cs" Inherits="txh" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>30周年同学会照片原生态无删减</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script type="text/javascript" src="scripts/bootstrap_v30/jquery/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="scripts/layer/layer.js"></script>
<link href="sheet/StyleSheet1.css" rel="stylesheet" />
<style type="text/css">
.auto-style1 {
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center" class="auto-style1">
<tr>
<td style="text-align: center">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</td>
</tr>
<tr>
<td style="text-align: center">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="<" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text=">" />
<br />
<asp:Image ID="Image1" runat="server" Height="100%" ImageAlign="Middle" Width="100%" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td style="text-align: center">
<asp:Timer ID="Timer1" runat="server" Interval="2000" OnTick="Timer1_Tick" Enabled="False">
</asp:Timer>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
C#代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Collections;
using System.Data;
public partial class txh : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string dirPath = HttpContext.Current.Server.MapPath("/imgtxh/");
if (Directory.Exists(dirPath))
{
//获得目录信息
DirectoryInfo dir = new DirectoryInfo(dirPath);
//获得目录文件列表
FileInfo[] files = dir.GetFiles("*.*");
this.Image1.ImageUrl = "~/imgtxh/" + files[0].Name;
}
}
}
protected void tpbind()
{
string dirPath = HttpContext.Current.Server.MapPath("/imgtxh/");
if (Directory.Exists(dirPath))
{
//获得目录信息
DirectoryInfo dir = new DirectoryInfo(dirPath);
//获得目录文件列表
FileInfo[] files = dir.GetFiles("*.*");
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
/*
string path = Server.MapPath("/imgtxh/");
DirectoryInfo di = new DirectoryInfo(path);
//找到该目录下的文件
//ImageUrl="~/imgtxh/1G5A7243.JPG"
FileInfo[] fis = di.GetFiles();
//ViewState["tpgs"]=fis.co
foreach (FileInfo fi in fis)
{
this.Image1.ImageUrl = "~/imgtxh/"+fi.Name;
this.Label1.Text = fi.Name;
// this.Image1.ImageUrl = path + fi.Name;
this.Timer1.Enabled = false;
break;
}
*/
}
protected void Button1_Click(object sender, EventArgs e)
{
string dirPath = HttpContext.Current.Server.MapPath("/imgtxh/");
if (Directory.Exists(dirPath))
{
//获得目录信息
DirectoryInfo dir = new DirectoryInfo(dirPath);
//获得目录文件列表
FileInfo[] files = dir.GetFiles("*.*");
int n = files.Length;//图片总数
//this.Image1.ImageUrl = "~/imgtxh/" + files[0].Name;
if(ViewState["tpsl"]!=null)
{
int wz = int.Parse(ViewState["tpsl"].ToString());//获取图片数量编号
try
{
if (wz <= 0)
{
this.Image1.ImageUrl = "~/imgtxh/" + files[0].Name;
}
else
{
ViewState["tpsl"] = wz - 1;
this.Image1.ImageUrl = "~/imgtxh/" + files[wz-1].Name;
}
}
catch
{
// this.Image1.ImageUrl
}
}
else //设置为第一章图片
{
ViewState["tpsl"] = 1;
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string dirPath = HttpContext.Current.Server.MapPath("/imgtxh/");
if (Directory.Exists(dirPath))
{
//获得目录信息
DirectoryInfo dir = new DirectoryInfo(dirPath);
//获得目录文件列表
FileInfo[] files = dir.GetFiles("*.*");
int n = files.Length;//图片总数
//this.Image1.ImageUrl = "~/imgtxh/" + files[0].Name;
if (ViewState["tpsl"] != null)
{
int wz = int.Parse(ViewState["tpsl"].ToString());//获取图片数量编号
try
{
if (wz>=n-1)
{
this.Image1.ImageUrl = "~/imgtxh/" + files[n-1].Name;
}
else
{
ViewState["tpsl"] = wz+1;
this.Image1.ImageUrl = "~/imgtxh/" + files[wz+1].Name;
}
}
catch
{
// this.Image1.ImageUrl
}
}
else //设置为第一章图片
{
ViewState["tpsl"] = 1;
}
}
}
}