This data source is divided into two parts. One is to call up data from the data class, and then operate the paging parameters and page paging auxiliary controls in this data source! There are three controls in front to control flip pages, one drop-down list and two linkbuttons!
The following fill () method is easy to call. You can simply rebind fill () on the page! But it must be written, for example, after the page turning action is executed!
The ds method in the DB class is as follows:
Public static datatable DS (string que)
{// Return a data table loaded with an SQL-based message,
Oledbconnection con = ODB. Con ();
Oledbdataadapter ODA = new oledbdataadapter ();
ODA. selectcommand = new oledbcommand (que, con );
Dataset DS = new dataset ();
ODA. Fill (DS, "thc ");
Return Ds. Tables ["thc"];
Con. Close ();
} The data source used in the following method is
Private void fill ()
{// Method, because there will be multiple bindings in the page
// Set a hidden label to store the current page index.
Int cup = convert. toint32 (pagelbl. Text );
Pageddatasource PS = new pageddatasource (); // a new paging Data Source
PS. datasource = ODB. DS ("select * From guest order by id desc "). defaultview; // send an SQL statement to confirm the data source of the data source.
PS. allowpaging = true; // allow pagination
PS. pagesize = 2; // set the number of pages
PS. currentpageindex = Cup-1;
If (! Ispostback)
{// Determine whether the page is loaded for the first time
For (INT I = 1; I <= ps. pagecount; I ++)
{// Loop page number
Pageddl. Items. Add (I. tostring ());
}
}
// The following mainly controls whether the up/down page button is used
Pageup. Enabled = true;
Pagedown. Enabled = true;
If (PS. isfirstpage)
{// If it is the first page, the previous page is unavailable
Pageup. Enabled = false;
}
If (PS. islastpage)
{// If it is the last page, the next page is unavailable
Pagedown. Enabled = false;
}
// Set the selected value in the page number drop-down menu
Pageddl. selecteditem. Text = Cup. tostring ();
// You can finally bind it to datalist.
Datalist1.datasource = Ps;
Datalist1.datakeyfield = "ID ";
Datalist1.databind ();
}
Next is how to handle page flip events.
Protected void pageddl_selectedindexchanged (Object sender, eventargs E)
{// Page number drop-down menu event
Pagelbl. Text = pageddl. selecteditem. Text. tostring ();
Fill ();
}
Protected void pagedown_click (Object sender, eventargs E)
{// Next page event
Pagelbl. Text = convert. tostring (convert. toint32 (pagelbl. Text) + 1 );
Fill ();
}
Protected void pageup_click (Object sender, eventargs E)
{// Previous event
Pagelbl. Text = convert. tostring (convert. toint32 (pagelbl. Text)-1 );
Fill ();
}