asp.net图片浏览器效果
技术来源于同学会实践 前台设计 <%@ 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; ????????????} ????????} ????} } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 从MVC中的资源获取[Display]属性值
- asp.net-mvc-3 – 首先是ASP.Net MVC 3 EF4.1代码 – 不支持
- asp.net-mvc – 可以在mvc JsonResult控制器方法上使用Outp
- asp.net – 如果我没有指定targetFramework =“4.0”会发生
- asp.net-mvc-3 – 使用jQuery验证货币字段的客户端验证
- IBatis.Net 老技术新研究
- asp.net-mvc-3 – EF 4.1 – 模型关系
- asp.net-mvc-5 – 使用MVC属性路由的每个控制器的多个Route
- asp.net-mvc – 使用ASP.Net MVC中的模型绑定器更新父/子记
- 初识WebAPI