As we all know, I will provide us with three data controls - DataGrid, Repeater, DataList. In these three controls, the DataGrid control is the most powerful, and the Repeater control is the most loyal to the template. The DataList control is both.
The DataGrid control is too famous, so there is also a lot of talks before, and the Repeater is too small, there is nothing to say. Here is mainly to talk about the DataList control.
The DataList control is also very powerful. He supports the choice, editing, and implementation. It is also very simple. ! !
It is indeed a very distressed thing.
However, DataList does not provide built-in paging function, but do not say, we can't use the DataList control to implement pagination, since it does not give me a paging function, then I have to do it.
Below is all original code, the method used by the method and the paging in the PHP are similar, just use the DataAdapter and DataSet combination, not the SQL statement in the PHP.
(This program is tested under .NET Framework Beta 2)
<% @ Page language = "c #"%>
<% @ Import namespace = "system.data"%>
<% @ Import namespace = "system.data.oledb"%>
/ *
Create By flying knife
http://www.aspcn.com
2001-7-25 01:44
Support .NET Framework Beta 2
* /
OLEDBCONNECTION MyConn;
Int PageSize, Recordcount, PageCount, CurrentPage
Public void Page_Load (Object SRC, Eventargs E)
{
/ / Setup Pagesize
PageSize = 10;
/ / Connection statement
String myconnstring = "provider = microsoft.jet.Oledb.4.0; data source =" server.mappath (".") "..// Database // db1.mdb;
MyConn = New OLEDBConnection (MyConnString);
Myconn.open ();
// First request execution
IF (! page.ispostback)
{
Listbind ();
CurrentPage = 0;
ViewState ["PageIndex"] = 0;
/ / How much record is calculated
Recordcount = CalculateRecord ();
LBLRecordcount.text = RecordCount.toString ();
/ / How many pages are calculated
PageCount = RecordCount / Pagesize;
LBLPAGECUNT.TEXT = pageCount.toString ();
ViewState ["PageCount"] = pagecount;
}
/ / How many records have been calculated
Public int coalculateRecord ()
{
int INTCOUNT;
String strcount = "select count (*) as co from score;
OLEDBCommand mycomm = new oledbcommand (strcount, myconn);
OLEDBDATAREADER DR = mycomm.executereader ();
IF (Dr.Read ())
{
INTCOUNT = INT32.PARSE (DR ["CO"]. TOSTRING ());
}
Else
{
INTCOUNT = 0;
}
Dr.close ();
Return Intcount;
}
ICollection createsource ()
{
Int StartIndex;
// Set the imported end of the end
StartIndex = CURRENTPAGE * PAGRENTPAGE
String strasel = "select * from score";
DataSet DS = New DataSet ();
OLEDBDataAdapter myadapter = new oledbdataadapter (strsel, myconn);
Myadapter.Fill (DS, StartIndex, Pagesize, "Score");
Return DS.Tables ["score"]. DefaultView;
}
Public void listbind ()
{
Score.DataSource = Createsource ();
Score.DATABIND ();
lbnnextpage.enabled = true;
lbnprevpage.enabled = true;
IF (CurrentPage == (PageCount-1)) LBnnextPage.enabled = false
IF (currentpage == 0) lbnprevpage.enabled = false;
LBLCurrentPage.Text = (CurrentPage 1) .tostring ();
}
Public void Page_ONCLICK (Object Sender, CommandEventArgs E)
{
CurrentPage = (int) ViewState ["PageIndex"];
PageCount = (int) ViewState ["PageCount"];
String cmd = e.commandname;
/ / Judgment CMD to determine the page direction
Switch (cmd)
{
Case "Next":
CurrentPage <(pagecount-1)) CurrentPage ;
Break;
Case "prev":
IF (CurrentPage> 0) CurrentPage--
Break;
}
ViewState ["PageIndex"] = CurrentPage;
Listbind ();
}
script>
hEAD>