博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
asp.net图片浏览器效果
阅读量:4634 次
发布时间:2019-06-09

本文共 4213 字,大约阅读时间需要 14 分钟。

技术来源于同学会实践

前台设计

<%@ 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;

            }

        }

    }

}

 

转载于:https://www.cnblogs.com/zrprj/p/11265371.html

你可能感兴趣的文章
Android WebView使用与JavaScript使用
查看>>
Axure 全局辅助线(转)
查看>>
图论之tarjan缩点
查看>>
C# 的快捷键汇总(一)
查看>>
正由另一进程使用,因此该进程无法访问此文件。
查看>>
linux简单优化
查看>>
洛谷 P1411 树
查看>>
打字游戏--飞机大战
查看>>
文本输入框、密码输入框
查看>>
内联式css样式,直接写在现有的HTML标签中
查看>>
HackerRank - Bricks Game
查看>>
Expect 教程中文版
查看>>
libcurl 客户端实例
查看>>
由Node.js事件驱动模型引发的思考
查看>>
easyUI样式之easyui-switchbutton
查看>>
在raspberry的jessie版系统上安装opencv3.0
查看>>
codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...
查看>>
maven笔记学习
查看>>
关于学习编程的一些看法
查看>>
oracle操作
查看>>