Default. aspx. CS
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. collections;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. Data. sqlclient;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
Bindtext ();
}
}
Protected void bindtext ()
{
Int pagesize = 20;
Int ipage;
If (request. querystring ["page"]! = NULL)
{
Ipage = convert. toint32 (request. querystring ["page"]);
}
Else
{
Ipage = 1;
}
Sqlconnection CNN = new sqlconnection (system. configuration. configurationmanager. connectionstrings ["CND"]. connectionstring );
Sqlcommand cmd = new sqlcommand ("infobuyw", CNN );
Cmd. commandtype = commandtype. storedprocedure; // The stored procedure is used here.
Cmd. Parameters. Add ("@ ipage", ipage );
Cmd. Parameters. Add ("@ ipagesize", pagesize );
Cmd. Parameters. Add ("@ ipagecount", sqldbtype. INT );
Cmd. Parameters ["@ ipagecount"]. Direction = parameterdirection. output;
CNN. open ();
Cmd. executenonquery ();
Int Re = (INT) (CMD. Parameters ["@ ipagecount"]. value );
A2.text = convert. tostring (CMD. Parameters ["@ ipagecount"]. value );
Sqldataadapter DAP = new sqldataadapter (CMD );
Dataset DST = new dataset ();
Dap. Fill (DST, "info ");
Pageddatasource PGDS = new system. Web. UI. webcontrols. pageddatasource ();
PGDS. datasource = DST. Tables ["info"]. defaultview;
This. ret8.datasource = PGDS;
This. databind ();
// set the allowed pagination
PGDS. allowpaging = true;
// 20 rows per page
PGDS. pagesize = pagesize;
// display the total number of pages
//
lbltotalpage. TEXT = PGDS. pagecount. tostring ();
// current page
int currentpage;
// The request page number is not null. Set the current page, otherwise, it is the first page
If (request. querystring ["page"]! = NULL)
{
Currentpage = convert. toint32 (request. querystring ["page"]);
}
Else
{
Currentpage = 1;
}
// The current page is directed to page number-1
PGDS. currentpageindex = currentpage-1;
// Display the current page number
Lblcurrentpage. Text = currentpage. tostring ();
// If it is not the first page, use the parameter page to set the previous page as the current page-1; otherwise, no connection is displayed.
If (ipage> 1)
{
// Request. currentexecutionfilepath is the virtual path of the current request
Lnkprev. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (currentpage-1 );
First. navigateurl = request. currentexecutionfilepath + "? Page = 1 ";
}
// End if
// If it is not the last page, use the parameter page to set the next page to the current page + 1; otherwise, the connection is not displayed.
If (ipage <Re)
{
// Request. currentexecutionfilepath is the virtual path of the current request
Lnknext. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (currentpage + 1 );
End. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (re );
}
Int pcount = Re;
Int pindex = convert. toint32 (currentpage );
Fenye. Text = strlink (pindex, pcount );
}
String strlink (INT pindex, int pcount)
{
Int pageturn = pindex + 10;
Int I;
String slink = NULL;
For (I = pindex; I <= pageturn; I ++)
{
If (I> pcount) break;
If (I! = Pindex)
{
Slink = slink + "<a href =? Page = "+ I. tostring () +"> "+ I. tostring () +" </a> & nbsp ;";
}
Else
{
Slink = slink + "" + I. tostring () + "& nbsp ;";
}
}
Return slink;
}
}
Default. aspx
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "head1" runat = "server">
<Title> ado-retepter </title>
<Link href = "ste.css" _ fcksavedurl = "" ste.css "" rel = "stylesheet" type = "text/CSS"/>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
& Nbsp; <asp: repeater id = "ret8" runat = "server">
<Itemtemplate> <div> <% # eval ("infoid") %> --------- <% # eval ("info_title ") %> </div> </itemtemplate> </ASP: repeater>
</Div>
<Br/>
<Asp: hyperlink id = "first" runat = "server"> homepage </ASP: hyperlink>
<Asp: hyperlink id = "lnkprev" runat = "server"> previous page </ASP: hyperlink>
<Asp: hyperlink id = "lnknext" runat = "server"> next page </ASP: hyperlink>
<Asp: hyperlink id = "end" runat = "server"> last page </ASP: hyperlink>
<Asp: Label id = "lblcurrentpage" runat = "server"> </ASP: Label>
Total pages
<Asp: Label id = "lbltotalpage" runat = "server"> </ASP: Label> page
<Asp: Label id = "fenye" runat = "server" text = "label"> </ASP: Label>
<Br/>
<Br/>
<Asp: Label id = "A2" runat = "server"> </ASP: Label>
</Form>
</Body>
</Html>
Stored Procedure buyinfow
Create procedure infobuyw
@ Ipagecount int output, -- total number of pages
@ Ipage int, -- current page number
@ Ipagesize int -- number of records per page
As
Set nocount on
Begin
-- Create a temporary table
Create Table # T (ID int identity, -- auto-increment Field
Infoid int, info_title varchar (200), cimg varchar (200), userid varchar (50), products_price varchar (50), company_name varchar (100), info_starttime smalldatetime)
-- Write data to the temporary table
Insert into # T
Select infoid, info_title, cimg, userid, products_price, company_name, info_starttime
From DBO. [Trade] Where info_type = 'supply 'and flag = '1'
Order by info_starttime DESC
-- Retrieve the total number of records
Declare @ irecordcount int
Set @ irecordcount = @ rowcount
-- Determine the total number of pages
If @ irecordcount % @ ipagesize = 0
Set @ ipagecount = ceiling (@ irecordcount/@ ipagesize)
Else
Set @ ipagecount = ceiling (@ irecordcount/@ ipagesize) + 1
-- If the requested page number is greater than the total page number, the last page is displayed.
If @ ipage> @ ipagecount
Select @ ipage = @ ipagecount
-- Determine the start and end records of the current page
Declare @ istart int -- start record
Declare @ iend int -- end record
Select @ istart = (@ ipage-1) * @ ipagesize
Select @ iend = @ istart + @ ipagesize + 1
-- Retrieve the current page record
Select * from # t where ID> @ istart and ID <@ iend
-- Delete a temporary table
Drop table # T
-- Total number of returned records
Return @ irecordcount
End
Go