C语言编程 - C++编程 - C#编程 - .NET编程 - JAVA编程 - VB编程 - DELPHI编程 - 汇编语言 - 数据结构 - ASP - PHP编程 - XML编程 - JSP
您现在的位置:首页--开发语言--.NET编程--Web Service--浏览文章

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

点击:   发布日期:2007-4-19 8:21:00   进入论坛
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);
参与讨论 关闭 返回顶部
>> 相关新闻
开发推荐
 
程序人生
 
数据库推荐
 
编程语言推荐
关于站点 - 联系我们 - 友情链接 - 版权隐私 - 免责声明 - BUG提交 - 网站导航 - 编程论坛 - 返回顶部

欢迎您在论坛发布各类原创作品和讨论话题,您的支持是自学编程网前进的基石    
copyright © 2005-2007 www.zxbc.cn online services. all rights reserved. Record No.:HN ICP No.07001293