- 热门文章:
- · 删除Access数词库中的空记录
- · ASP上两个防止SQL注入式攻击Function
- · DataGrid 分页问题 -- 无法响应 PageIndexChanged 事件
- · ADO三大对象的属性、方法、事件及常数
- · Asp数据库访问代码自动产生工具-ASPRunner(适用初学者和为了提高开发效率的Developer)
- · Connection 对象
- · 如何在ado中使用connection 对象什么是connection对象?
- · 数据验证之特殊字符处理
- · 如何让DataGrid自动生成序号
- · 几个小时后,我学数据库,找到一些代码
- · DataGrid自定义分页存储过程
- · Asp 单页查询数据库!
Repeater显示数据的例子,带分页
下面是个Repeater显示数据分页的例子
我在做时候遇到的问题给大家提一下刚开始我使用DataReader做数据源,是不行,后才换DataSet
在设置分页的时候一定要搞清楚当前页,如果你把当前页设置成1,那么他就从第二页显示数据了,因为它的当前页是从0开始的,而我们显示当前页时候是从1开始的
在比较是否达到总页数之前一定要先也给PS设置数据源,我就是先用ps.CurrentPageIndex==ps.PageCount-1检查是否在最后一页,然后再ps.DataSource=ds.Tables["authors"].DefaultView;设置数据源的,结果分页一直有问题.
呵呵,这几个问题搞了我半天。可能是我太菜了吧,学.NET还没多久呢。
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace test
{
/// <summary>
/// Repeater 的摘要说明。
/// </summary>
public class Repeater : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label lbCurPage;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Repeater Repeater1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
this.lbCurPage.Text="1";
this.BindToRepeater();
}
}
private void BindToRepeater()
{
SqlConnection con=new SqlConnection("data source=.;database=pubs;uid=sa;pwd=123a456b");
// SqlCommand cmd=new SqlCommand("select * from authors",con);
// con.Open();
// SqlDataReader dr;
// dr=cmd.ExecuteReader();
SqlDataAdapter da=new SqlDataAdapter("select * from authors",con);
DataSet ds=new DataSet();
da.Fill(ds,"authors");
PagedDataSource ps=new PagedDataSource();
ps.AllowPaging=true;
ps.PageSize=5;
this.Repeater1.DataSource=ps;
ps.CurrentPageIndex=Convert.ToInt32(this.lbCurPage.Text)-1;
ps.DataSource=ds.Tables["authors"].DefaultView;
this.Button1.Enabled=true;
this.Button2.Enabled=true;
if(ps.CurrentPageIndex==0)
{
this.Button1.Enabled=false;
}
if(ps.CurrentPageIndex==ps.PageCount-1)
{
this.Button2.Enabled=false;
}
this.Repeater1.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
this.lbCurPage.Text=Convert.ToString(Convert.ToInt32(this.lbCurPage.Text)-1);
this.BindToRepeater();
}
private void Button2_Click(object sender, System.EventArgs e)
{
this.lbCurPage.Text=Convert.ToString(Convert.ToInt32(this.lbCurPage.Text)+1);
this.BindToRepeater();
}
}
}
- · 用WEB(ASP)方式实现SQL SERVER 数据库的备份和恢复
- · Asp备份与恢复SQL Server数据库
- · XP 风格的可拖动列、可排序、可改变宽度的DataGrid的例子
- · datagrid编辑、修改、删除、翻页例子
- · DataGrid脚眉显示合计
- · datagrid编辑、修改、删除、翻页例子
- · 把dataset作为一个xml文件传给客户端
- · OLEDB Resource(Session) Pooling (在Ado开发中使用连接池)
- · DataReader使用
- · asp + oracle 分页方法 (不用存储过程)
- · 关于DropDownList绑定数据的一点认识
- · 在ASP中处理数据库的NULL记录
- · 求解在SQL中使用了where列所遇到的问题
- · asp + sqlserver 分页方法(不用存储过程)
- · 用的ASP防SQL注入攻击程序
- · MySQL数据库基础教程
- · ASP和SQLServer时间处理方法Ⅰ
- · 在SQL Server中保存和输出图片
- · 用ASP实现文档资料管理
- · ASP连接数据库的5种方法
- · 随机提取数据库记录
- · 常用Response对象的使用详解
- · 在DataGrid中删除记录时弹出确认窗口
- · SQL Server CHARINDEX和PATINDEX详解
- · DataGrid单击一行改变此行背景色
- · [分享]解决Access错误 Selected collating sequence not supported by the operating system
- · 如何使用标签显示完整的svg图像?
- · datagrid与DataSet结合使用中出现的索引问题
- · web.config配置web应用程序中的数据库连接
- · ASP构造大数据量的分页SQL语句
- · 方便的使用单击和双击更新DataGrid中的数据的例子
- · 一个离线ADO数据管理模块的实现
- · DataGrid在PostBack后定位记录的简单办法
- · DataGrid和存储过程结合的分页,只读取当前页数据
- · 利用Application和Session优化Asp的数据库联接
- · 动态载入树 (ASP+数据库)
- · 解决使用ASP无法连接 ORACLE 9i 数据库的问题。
- · 一次编程实践[ASP+MSSQL]
