The repeater and datalist controls can quickly and flexibly display data on the. ASPX page,
Neither of them has the paging function. Although the DataGrid Control has the paging function, it is too flexible to use.
Many articles are discussing the paging functions of repeater and datalist. We will use
The pagedatasource class is paginated in repeater:
Pagedatasource is a class encapsulated in the DataGrid, which is used to implement the paging function;
You can also use this class to pagination in datalist and repeater.
The problem can be solved.
<% @ Import namespace = "system. Data" %>
<% @ Import namespace = "system. Data. sqlclient" %>
<HTML>
<Head>
<Title> default </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Script language = "C #" runat = "server">
Public void page_load (Object SRC, eventargs E)
{Sqlconnection CNN = new sqlconnection ("Server = zzl; uid = sa; Pwd = 970480; database = zzl"); // connect to the database
Sqldataadapter mycommand = new sqldataadapter ("select * From start1", CNN); // data operations are performed on the start1 table and its data in sqlserver.
Dataset DS = new dataset ();
Mycommand. Fill (DS); // The DataSet object of the instance is DS, and the data is filled to DS.
Pageddatasource pp = new pageddatasource (); // class instance object of the paging Function
Pp. datasource = Ds. Tables [0]. defaultview; // assign data to the object PP
Pp. allowpaging = true; // pagination allowed
Pp. pagesize = 6; // set the number of data entries per page
Int cpage; // The integer used to analyze the number of pages
If (request. querystring ["page"]! = NULL) // This judgment statement is used to assign values to the cpage.
Cpage = convert. toint32 (request. querystring ["page"]);
Else
Cpage = 1;
Pp. currentpageindex = cpage-1; // The current index value of the PP object, because the index value starts from 0 and cpage starts from 1.
If (! Pp. isfirstpage) // request. currentexecutionfilepath is the file name of the current program, which can be directly written.
Pre. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (cpage-1 );
If (! Pp. islastpage)
Next. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (cpage + 1 );
Repeater1.datasource = pp;
Repeater1.databind ();}
</SCRIPT>
</Head>
<Body>
<Table width = "100%" border = "0">
<Tr> <TD> & nbsp; <asp: Label id = "current" runat = "server"/> </TD> </tr>
<Tr> <TD> & nbsp; <asp: hyperlink id = "pre" runat = "server"> </ASP: hyperlink>
<Asp: hyperlink id = "Next" runat = "server"> </ASP: hyperlink> </TD> </tr> </table>
<Asp: repeater id = "repeater1" runat = "server">
<Itemtemplate>
<Table width = "100%" border = "0">
<Tr> <TD> & nbsp; <% # databinder. eval (container. dataitem, "product") %> </TD> </tr>
<Tr> <TD> & nbsp; </TD> </tr> </table> </itemtemplate> </ASP: repeater>
</Body>
</Html>