转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> Access >> 正文
DataGrid连接Access的快速分页法(5)——实现快速分页         ★★★★

DataGrid连接Access的快速分页法(5)——实现快速分页

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1504 更新时间:2009/4/22 21:27:57

  DataGrid连接Access的快速分页法(5)——实现快速分页

我使用Access自带的Northwind中文数据库的“订单明细”表作为例子,不过我在该表添加了一个名为“Id”的字段,数据类型为“自动编号”,并把该表命名为“订单明细表”。

FastPaging_DataSet.ASPx
--------------------------------------------------------------------------------------
<%@ Page language="c#" Codebehind="FastPaging_DataSet.ASPx.cs" AutoEventWireup="false" Inherits="Paging.FastPaging_DataSet" EnableSessionState="False" enableViewState="True" enableViewStateMac="False" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DataGrid + DataReader 自定义分页</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="javascript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form runat="server">
<ASP:datagrid id="DataGrid1" runat="server" BorderWidth="1px" BorderColor="Black" Font-Size="12pt"
AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-BackColor="#aaaadd" PagerStyle-HorizontalAlign="Right"
CellPadding="3" AllowPaging="True" AllowCustomPaging="True" AutoGenerateColumns="False" OnPageIndexChanged="MyDataGrid_Page"
PageSize="15" AllowSorting="True" OnSortCommand="DataGrid1_SortCommand">
<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
<ItemStyle Font-Size="Smaller" BorderWidth="22px"></ItemStyle>
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<ASP:BoundColumn DataField="ID" SortExpression="ID" HeaderText="ID"></ASP:BoundColumn>
<ASP:BoundColumn DataField="订单ID" HeaderText="订单ID"></ASP:BoundColumn>
<ASP:BoundColumn DataField="产品ID" HeaderText="产品ID"></ASP:BoundColumn>
<ASP:BoundColumn DataField="单价" HeaderText="单价"></ASP:BoundColumn>
<ASP:BoundColumn DataField="数量" HeaderText="数量"></ASP:BoundColumn>
<ASP:BoundColumn DataField="折扣" HeaderText="折扣"></ASP:BoundColumn>
</Columns>
<PagerStyle Font-Names="VerDana" Font-Bold="True" HorizontalAlign="Right" ForeColor="Coral"
Mode="NumericPages"></PagerStyle>
</ASP:datagrid></form>
</body>
</HTML>


FastPaging_DataSet.ASPx.cs
--------------------------------------------------------------------------------------
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.OleDb;
using System.Text;

namespace Paging
{
public class FastPaging_DataSet : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;

const String QUERY_FIELDS = "*"; //要查询的字段
const String TABLE_NAME = "订单明细表"; //数据表名称
const String PRIMARY_KEY = "ID"; //主键字段
const String DEF_ORDER_TYPE = "ASC"; //默认排序方式
const String SEC_ORDER_TYPE = "DESC"; //可选排序方式
const String CONDITION = "产品ID='AV-CB-1'";

OleDbConnection conn;
OleDbCommand cmd;
OleDbDataAdapter da;

#region 属性

#region CurrentPageIndex
/// <summary>
/// 获取或设置当前页的索引。
/// </summary>
public int CurrentPageIndex
{
get { return (int) ViewState["CurrentPageIndex"]; }
set { ViewState["CurrentPageIndex"] = value; }
}
#endregion

#region OrderType
/// <summary>
/// 获取排序的方式:升序(ASC)或降序(DESC)。
/// </summary>
public String OrderType
{
get {
String orderType = DEF_ORDER_TYPE;
if (ViewState["OrderType"] != null) {
orderType = (String)ViewState["OrderType"];
if (orderType != SEC_ORDER_TYPE)
orderType = DEF_ORDER_TYPE;
}
return orderType;
}
set { ViewState["OrderType"] = value.ToUpper(); }
}
#endregion

#endregion

private void Page_Load(object sender, System.EventArgs e)
{
#region 实现
String strConn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="
+ Server.MapPath("Northwind.mdb");
conn = new OleDbConnection(strConn);
cmd = new OleDbCommand("",conn);
da = new OleDbDataAdapter(cmd);

if (!IsPostBack) {
// 设置用于自动计算页数的记录总数
DataGrid1.VirtualItemCount = GetRecordCount(TABLE_NAME);

CurrentPageIndex = 0;
BindDataGrid();
}
#endregion
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private void BindDataGrid()
{
#region 实现
// 设


[其他]手工升级ACCESS到SQLSERVER方法详解  [Web开发]把ACCESS的数据导入到Mysql中的方法详解
[C语言系列]SQL Server连接ACCESS数据库的实现  [C语言系列]应用 SQLServer 链接服务器访问远程 Access 数据库
[VB.NET程序]WindowsForm登陆窗体的制作(Vb.net+Access)  [VB.NET程序]在VB.NET中使用MS Access存储过程 — 第二部份
[VB.NET程序]在VB.NET中使用MS Access存储过程 — 第一部份  [VB.NET程序]如何在Visual Basic 6.0 中连接加密的Access数据库
[Delphi程序]Delphi Access violations 问题的解决之道  [Delphi程序]Delphi操作ACCESS技巧集
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台