Mode = "numericpages"> pageerstyle>
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 = "*"; // to query the field
const string Table_name = "Order Ming Fine Table"; // Data Sheet Name
Const string primary_key = "id"; // primary key field
const string def_order_type = "ASC"; // Default Sort by
Const string sec_order_type = "dec"; // Optional sorting method
Const string condition = "Product ID = 'AV-CB-1'";
OLEDBCONNECTION CONN;
OLEDBCOMMAND CMD;
OLEDBDataAdapter DA;
#region attribute
#Region CurrentPageIndex
///
/// Get or set the index of the current page.
/// summary>
Public Int CurrentPageIndex
{
Get {return (int) ViewState ["currentpageindex"];
Set {ViewState ["CurrentPageIndex"] = Value;
}
#ndregion
#Region Ordertype
///
/// Get sorted mode: Ascending order (ASC) or descending (DESC).
/// summary>
Public String Ordetepe
{
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 ();}
}
#ndregion
#ndregion
Private Void Page_Load (Object Sender, System.EventArgs E)
{
#Region implementation
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) {
// Set the total number of records used to automatically calculate the page DataGrid1.virtualItemcount = getRecordcount (Table_name);
CurrentPageIndex = 0;
BinddataGrid ();
}
#ndregion
}
#Region web form designer generated code
Override protected void oninit (Eventargs E)
{
//
// Codegen: This call is necessary for the ASP.NET Web Form Designer.
//
InitializationComponent ();
Base.onit (E);
}
///
/// Designer supports the required method - do not use the code editor to modify
/// This method is content.
/// summary>
Private vidinitiRizeComponent ()
{
This.Load = New System.EventHandler (this.page_load);
}
#ndregion
Private void binddatagrid ()
{
#Region implementation
/ / Set the index of the current page
DataGrid1.currentpageIndex = CurrentPageIndex;
// Set the data source
DataGrid1.datasource = getDataView ();
DataGrid1.databind ();
#ndregion
}
///
/// Total the total number of records in the database table.
/// summary>
/// The name of the table in the database. param>
/// success is the total number of records in the table; otherwise be -1. returns>
Private int getRecordcount (String Tablename)
{
#Region implementation
INT country;
CMD.comMandtext = "Select count (*) as recordcount from" TABLENAME;
Try {
Cn.open ();
Count = Convert.Toint32 (cmd.executescalar ());
} catch (exception ex) {
Response.write (ex.Message.toString ());
count = -1;
} finally {
CONN.CLOSE ();
}
Return count;
#ndregion
}
Private dataView getDataView ()
{
#Region implementation
INT Pagesize = DataGrid1.pageSize;
DataSet DS = New DataSet ();
DataView DV = NULL;
cmd.comMandtext = fastpaging.paging (
PageSize,
CurrentPageIndex,
DataGrid1.virtualItemcount,
Table_name,
Query_fields,
PRIMARY_KEY,
FastPaging.Isascending (Ordertype));
Try {
Da.fill (DS, Table_name);
DV = ds.tables [0] .defaultView;
} catch (exception ex) {
Response.write (ex.Message.toString ());
}
Return DV; #ndregion
}
Protected void myDataGrid_page (Object Sender, DataGridPageChangeDeventargs E)
{
CurrentPageIndex = E.NewpageIndex;
BinddataGrid ();
}
Protected void DataGrid1_sortcommand (Object Source, DataGridSortCommandeventEventArgs E)
{
#Region implementation
DataGrid1.currentpageIndex = 0;
THIS.CURRENTPAGEINDEX = 0;
IF (Ordertype == Def_ORDER_TYPE)
ORDERTYPE = SEC_ORDER_TYPE;
Else
ORDERTYPE = DEF_ORDER_TYPE;
BinddataGrid ();
#ndregion
}
}
}
I have to introduce the DataGrid connection ACCESS's fast paging method here. If you have other better paging methods, it is better to share it with you!
The younger brother wrote the article for the first time, there is something wrong, I hope everyone will correct.
Author: Tripoli
Mailbox: itfun@163.com