利用ASP.NET動態產生Meta資訊讓GridView每隔一段時間自動換頁,並且加入"淡出淺入"效果

在"利用ASP.NET AJAX的Timer讓GridView每隔一段時間做到自動換頁的功能"這篇文章裡
介紹到如何利用ajax的timer做到gridview自動換頁的功能,但有人提到換頁可否加入"淡出淺入"的效果
小弟就利用另一方式來換頁,也就是利用"ASP.NET動態產生meta資訊的應用,時間倒數10秒去另一網頁"這篇的方式換頁

在"利用ASP.NET AJAX的Timer讓GridView每隔一段時間做到自動換頁的功能"這篇文章裡

介紹到如何利用ajax的timer做到gridview自動換頁的功能,但有人提到換頁可否加入"淡出淺入"的效果

小弟就利用另一方式來換頁,也就是利用"ASP.NET動態產生meta資訊的應用,時間倒數10秒去另一網頁"這篇的方式換頁

並且加入"淡出淺入"的效果,如下所示(只要在網頁加入下列程式碼就有"淡出淺入"的效果了)

    <meta http-equiv="Page-Exit" content="revealTrans(Duration=1.0,Transition=23)" />
    <meta http-equiv="Page-Enter" content="revealTrans(Duration=1.0,Transition=23)" />

asp.net(c#)

完整程式碼:

GridViewPage.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewPage.aspx.cs" Inherits="GridViewPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>GridViewPage</title>
    <%--加入"隨機"換頁效果--%>
    <meta http-equiv="Page-Exit" content="revealTrans(Duration=1.0,Transition=23)" />
    <meta http-equiv="Page-Enter" content="revealTrans(Duration=1.0,Transition=23)" />
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="1">
            </asp:GridView>
        </div>
    </form>
</body>
</html>

GridViewPage.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class GridViewPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();

            int page = 0;

            if (Request.QueryString["page"] != null)
            {
                page = int.Parse(Request.QueryString["page"]);
            }




            if (this.GridView1.PageCount > 1)
            {
                this.GridView1.PageIndex = page;
                LoadData();

                if (page == this.GridView1.PageCount - 1)
                {
                    LoadPage(0);
                }

                else
                {
                    LoadPage(page + 1);
                }

            }


        }

    }


    //每隔5秒換一次頁
    protected void LoadPage(int page)
    {
        HtmlMeta meta = new HtmlMeta();
        meta.Attributes.Add("http-equiv", "refresh");
        meta.Content = "5; url=GridViewPage.aspx?page=" + page;
        this.Header.Controls.Add(meta);
    }


    //載入資料
    protected void LoadData()
    {
        this.GridView1.DataSource = new string[] { "Dotblogs", "F6 Team", "puma" };
        this.GridView1.DataBind();
    }

}

執行結果:

←有加入"淡出淺入"的效果,自己run看看喔..

參考網址:

http://www.dotblogs.com.tw/puma/archive/2008/05/06/3811.aspx

http://www.newspace.com.tw/free/page/10.asp

http://www.dotblogs.com.tw/puma/archive/2008/05/09/3912.aspx

http://www.blueshop.com.tw/board/show.asp?subcde=BRD20080505105530IWC&fumcde=FUM20041006161839LRJ#BRD200805062248149SW%5C