利用ASP.NET AJAX的Timer讓GridView每隔一段時間做到自動換頁的功能
最近在討論區看到這個問題,小弟利用asp.net ajax的timer來實作這個功能
利用timer每隔一段時間,讓gridview自動跳頁並且更新gridview的內容
asp.net(c#)
GridviewAutoPage.aspx
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每隔一段時間做到自動換頁的功能的更多相关文章
- flask中使用ajax 处理前端请求,每隔一段时间请求不通的接口,结果展示同一页面
需求: flask中使用ajax 处理前端请求,每隔一段时间请求不通的接口,结果展示同一页面 用到 setTimeout方法,setTimeout(function(){},1000):setTime ...
- flask中使用ajax 处理前端请求,每隔一段时间请求一次
需求: flask中使用ajax 处理前端请求,每隔一段时间请求一次,并展示在页面 使用 setInterval(function(){},1000)方法 结果展示: html:(test.html) ...
- 利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. 先来个简单的实例热热身吧. 1.无参数的方法调用 asp.net code: view plaincopy to clip ...
- ASP.NET AJAX入门系列(10):Timer控件简单使用
本文主要通过一个简单示例,让Web页面在一定的时间间隔内局部刷新,来学习一下ASP.NET AJAX中的服务端Timer控件的简单使用. 主要内容 Timer控件的简单使用 1.添加新页面并切换到设计 ...
- AspNetPager + GridView + ASP.NET AJAX 分页无刷新实现
准备资源: AspNetPager 下载网址:http://www.webdiyer.com/download/default.aspx ASP.NET AJAX 下载网址:http://www.a ...
- 类型:Jquery;问题:jquery调用后台带参数方法;结果:利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法。
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. [WebMethod] 命名空间 1.无参数的方法调用, 注意:1.方法一定要静态方法,而且要有[WebMethod] ...
- 【初学者指南】在ASP.NET MVC 5中创建GridView
介绍 在这篇文章中,我们将会学习如何在 ASP.NET MVC 中创建一个 gridview,就像 ASP.NET Web 表单中的 gridview 一样.服务器端和客户端有许多可用的第三方库,这些 ...
- (译)利用ASP.NET加密和解密Web.config中连接字符串
介绍 这篇文章我将介绍如何利用ASP.NET来加密和解密Web.config中连接字符串 背景描述 在以前的博客中,我写了许多关于介绍 Asp.net, Gridview, SQL Server, A ...
- 利用ASP.NET加密和解密Web.config中连接字符串
摘自:博客园 介绍 这篇文章我将介绍如何利用ASP.NET来加密和解密Web.config中连接字符串 背景描述 在以前的博客中,我写了许多关于介绍 Asp.net, Gridview, SQL Se ...
随机推荐
- 【POJ1330】Nearest Common Ancestors(树链剖分求LCA)
Description A rooted tree is a well-known data structure in computer science and engineering. An exa ...
- win7 热点设置命令
netsh wlan set hostednetwork mode=allownetsh wlan set hostednetwork ssid=XXXX key=XXXnetsh wlan star ...
- 移植qt5.3.1到arm
最近刚入手一款开发板(比较低端,刚毕业工作还没一个月,穷屌丝一个).在学校以前都是用的是Friendly Arm的6410,使用的qt版本是使用的最多的4.7.0版本,入手的板子是4.7.4.qt5出 ...
- QPixmap有缓冲区的
我想qt 中QPixmap这个类大家都很熟悉,它可以很简单的在标签上贴图:例如: QPixmap p; p.load("1.png"): label->setPixmap(p ...
- [LeetCode#263]Factorial Trailing Zeroes
Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positiv ...
- Linux Shell编程(19)——测试与分支
case和select结构在技术上说不是循环,因为它们并不对可执行的代码块进行迭代.但是和循环相似的是,它们也依靠在代码块的顶部或底部的条件判断来决定程序的分支.在代码块中控制程序分支case (in ...
- Linux Shell编程(14)——内部变量
内建变量影响Bash脚本行为的变量.$BASHBash二进制程序文件的路径 bash$ echo $BASH /bin/bash$BASH_ENV该环境变量保存一个Bash启动文件路径,当启动一个脚本 ...
- ACM2075_A/B
#include<iostream> int main() { using namespace std; int i,j,count; cin>>count; while(co ...
- Treasure Hunt - POJ 1066(线段相交判断)
题目大意:在一个正方形的迷宫里有一些交错墙,墙的两端都在迷宫的边缘墙上面,现在得知迷宫的某个位置有一个宝藏,所以需要砸开墙来获取宝藏(只能砸一段墙的中点),问最少要砸开几面墙. 分析:这个题意刚开 ...
- JDBC基本知识
JDBC的作用 JDBC为java访问数据库提供通用的API,可以为多种关系数据库提供统一访问.因为SQL是关系式数据库管理系统的标准语言,只要我们遵循SQL规范,那么我们写的代码既可以访问MySQL ...