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;