Because the pages of the previous CF, JavaScript, PHP, and ASP pages are basically the same, yesterday C #. Net went a lot better, that is, Code Copy and paste the file directly into vs.net, and write a class.
It's easy to use. The calling method is roughly as follows:
ProgramCode Protected void databind (){
Int page = 1;
If (request. querystring ["page"]! = NULL ){
Page = convert. toint32 (request ["page"]);
}
If (request. Form ["page"]! = NULL ){
Page = convert. toint32 (request. Form ["page"]);
}
Int mypagesize = 20;
Sqlconnection conn = new sqlconnection (dbtool. myconnstr );
Sqlcommand cmd = new sqlcommand ("p_page", Conn );
Cmd. commandtype = commandtype. storedprocedure;
Cmd. Parameters. Add ("@ tables", sqldbtype. varchar, 50 );
Cmd. Parameters ["@ tables"]. value = "testtable ";
Cmd. Parameters. Add ("@ primarykey", sqldbtype. varchar, 50 );
Cmd. Parameters ["@ primarykey"]. value = "ID ";
Cmd. Parameters. Add ("@ sort", sqldbtype. varchar, 50 );
Cmd. Parameters ["@ sort"]. value = "id ASC ";
Cmd. Parameters. Add ("@ currentpage", sqldbtype. Int, 4 );
Cmd. Parameters ["@ currentpage"]. value = page;
Cmd. Parameters. Add ("@ pagesize", sqldbtype. Int, 4 );
Cmd. Parameters ["@ pagesize"]. value = mypagesize;
Cmd. Parameters. Add ("@ fields", sqldbtype. varchar, 50 );
Cmd. Parameters ["@ fields"]. value = "ID, username ";
Cmd. Parameters. Add ("@ filter", sqldbtype. varchar, 50 );
Cmd. Parameters ["@ filter"]. value = "id> 1000 and ID <10000 ";
Cmd. Parameters. Add ("@ group", sqldbtype. varchar, 50 );
Cmd. Parameters ["@ group"]. value = "";
Cmd. Parameters. Add ("@ totalpage", sqldbtype. Int, 4 );
Cmd. Parameters ["@ totalpage"]. Direction = parameterdirection. output;
Cmd. Parameters. Add ("@ totalrecord", sqldbtype. Int, 4 );
Cmd. Parameters ["@ totalrecord"]. Direction = parameterdirection. returnvalue;
Conn. open ();
// Obtain the returned value first
Cmd. executenonquery ();
Int totalpage, totalrecord;
Totalpage = convert. toint32 (CMD. Parameters ["@ totalpage"]. value );
Totalrecord = convert. toint32 (CMD. Parameters ["@ totalrecord"]. value );
// Obtain the returned record set
Sqldatareader SDR = cmd. executereader ();
Gridview1.datasource = SDR;
Gridview1.databind ();
Cmd. Dispose ();
Conn. Dispose ();
Tools mytool = new tools (response, request );
/*
* Function: pagelink displays paging navigation.
* Totalcount: Total number of records
* Totalpage: Total number of pages
* Page: page number
* Perpagesize: number of records displayed on each page
* Groupsizes: Number of pages displayed on each group
* Pageargu: Paging Parameters
* Showgoto: whether to display the jump
*/
Lblpagelink. Text = mytool. pagelink (totalrecord, totalpage, page, mypagesize, 3, "page", true );
Mytool. Dispose ();
}