最近在討論區看到這個問題,小弟利用asp.net ajax的timer來實作這個功能

利用timer每隔一段時間,讓gridview自動跳頁並且更新gridview的內容

asp.net(c#)

GridviewAutoPage.aspx

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

<!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>GridviewAutoPage</title>
    <meta http-equiv="Page-Enter" content="blendTrans(duration=1)" />
    <meta http-equiv="Page-Exit" content="blendTrans(duration=1)" />
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="1">
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
        <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
        </asp:Timer>
    </form>
</body>
</html>

GridviewAutoPage.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 GridviewAutoPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

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

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        if (this.GridView1.PageCount > 1)
        {
            if (this.GridView1.PageIndex == this.GridView1.PageCount - 1)
            {
                this.GridView1.PageIndex = 0;
                LoadData();
            }
            else
            {
                this.GridView1.PageIndex = this.GridView1.PageIndex + 1;
                LoadData();
            }
        }
    }
}

執行結果:

转自:http://www.cnblogs.com/scy251147/archive/2010/08/10/1796673.html

利用ASP.NET AJAX的Timer讓GridView每隔一段時間做到自動換頁的功能的更多相关文章

  1. flask中使用ajax 处理前端请求,每隔一段时间请求不通的接口,结果展示同一页面

    需求: flask中使用ajax 处理前端请求,每隔一段时间请求不通的接口,结果展示同一页面 用到 setTimeout方法,setTimeout(function(){},1000):setTime ...

  2. flask中使用ajax 处理前端请求,每隔一段时间请求一次

    需求: flask中使用ajax 处理前端请求,每隔一段时间请求一次,并展示在页面 使用 setInterval(function(){},1000)方法 结果展示: html:(test.html) ...

  3. 利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法

    利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. 先来个简单的实例热热身吧. 1.无参数的方法调用 asp.net code: view plaincopy to clip ...

  4. ASP.NET AJAX入门系列(10):Timer控件简单使用

    本文主要通过一个简单示例,让Web页面在一定的时间间隔内局部刷新,来学习一下ASP.NET AJAX中的服务端Timer控件的简单使用. 主要内容 Timer控件的简单使用 1.添加新页面并切换到设计 ...

  5. AspNetPager + GridView + ASP.NET AJAX 分页无刷新实现

    准备资源: AspNetPager 下载网址:http://www.webdiyer.com/download/default.aspx ASP.NET AJAX  下载网址:http://www.a ...

  6. 类型:Jquery;问题:jquery调用后台带参数方法;结果:利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法。

    利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. [WebMethod]   命名空间 1.无参数的方法调用, 注意:1.方法一定要静态方法,而且要有[WebMethod] ...

  7. 【初学者指南】在ASP.NET MVC 5中创建GridView

    介绍 在这篇文章中,我们将会学习如何在 ASP.NET MVC 中创建一个 gridview,就像 ASP.NET Web 表单中的 gridview 一样.服务器端和客户端有许多可用的第三方库,这些 ...

  8. (译)利用ASP.NET加密和解密Web.config中连接字符串

    介绍 这篇文章我将介绍如何利用ASP.NET来加密和解密Web.config中连接字符串 背景描述 在以前的博客中,我写了许多关于介绍 Asp.net, Gridview, SQL Server, A ...

  9. 利用ASP.NET加密和解密Web.config中连接字符串

    摘自:博客园 介绍 这篇文章我将介绍如何利用ASP.NET来加密和解密Web.config中连接字符串 背景描述 在以前的博客中,我写了许多关于介绍 Asp.net, Gridview, SQL Se ...

随机推荐

  1. h.264宏块与子宏块类型

    宏块类型mb_type 宏块类型表示的是宏块不同的分割和编码方式,在h.264的语法结构中,宏块类型在宏块层(macroblock_layer)中用mb_type表示(请参考h.264语法结构分析中的 ...

  2. 遍历、显示ftp下的文件夹和文件信息

    今天做了通过ftp读取ftp根目录下的所有文件夹和文件,嵌套文件夹查询,总共用到了一下代码: 1.FtpFile_Directory package com.hs.dts.web.ftp; impor ...

  3. 利用ROWID快速执行关联更新

    一.构造相关表P1,P2 create table p1(id int,name char(10)); create table p2(id int,name char(10)); 二.批量插入数据 ...

  4. 关于IN-LIST迭代

    IN-list iterator (IN-list迭代) 字段有索引,in里有多少个值就执行多少次索引扫描.不管值是否在字段里存在~ SQL> create table t1 as select ...

  5. zoj 3088 Easter Holidays(最长路+最短路+打印路径)

    Scandinavians often make vacation during the Easter holidays in the largest ski resort Are. Are prov ...

  6. 关于The APR based Apache Tomcat Native library警告

    今天在Eclipse上配置Tomcat7,启动时看到如下警告信息: The APR based Apache Tomcat Native library which allows optimal pe ...

  7. Web服务器性能/压力测试工具http_load、webbench、ab、Siege使用教程 - VPS侦探

    Web服务器性能/压力测试工具http_load.webbench.ab.Siege使用教程 - VPS侦探 http://soft.vpser.net/test/http_load/http_loa ...

  8. Ubuntu 下安装opencv 编译后执行找不到库

    在ubuntu下编译opencv程序后,执行报下面到错误:error while loading shared libraries: libopencv_core.so.2.4: cannot ope ...

  9. Bridges painting - SGU 121(构造)

    题目大意:有个一无向图,给所有的边染色,如果一个点连接的边超过两个,那么最少要染一个白色和一个黑色,能否给整个图染色?不能输出“No solution”. 分析:引用连接 http://edward- ...

  10. div样式调整小结 转载

    1.多个div使用会自动换行,应该使用float属性  left : 对象浮在左边  right : 对象浮在右边 例如:  float: left  和 float: right 是两个div左右排 ...