Problem: In ASP.NET, paging navigation seems to be very simple, do some simple settings using DataGrid. But careful programmers will not like this way, because each of this way is required to place all data into the DataGrid and select Several data from the corresponding page. When the amount of data is large, the speed will become a problem. Another disadvantage is that the page style is that it will become ugly when the number of records of the last page is smaller than the number of entries set.
Technical Analysis: What we need is to query the record of the current page and display it according to the set style. Here is two questions: First, the database query, how to dynamically query the specific data of the specific page; the second is the problem that the display is displayed, you need to write a function to implement the features of the page-level navigation.
MySQL, Oracle databases have their own SQL statements that specify start and end records in their own query database. But I really want the SQL Server database only Top keywords to query the first few records. But there is no relationship, we can use this to create a SQL statement that specifies the start and end record in the query database:
Definition Page: Current page; PageSize: The number of regions per page;
Select Top PageSize from MyTable
WHERE ID NOT IN
SELECT TOP PAGESIZE * (PAGE-1) from MyTable
ORDER BY ID
)
ORDER BY ID
This is just a query without query conditions. If you need to query conditions, you can remember that you should not forget to add query conditions in both.
The second step is to write a PAGE class to implement the features of the pagination navigation. One of the methods: public string Pagelist (String Strtitle, String Strtab, String [] FLDS, String [] Cols, String Strin, Int Pagesize, int StartIndex
STRTILE: Title of page navigation, for example, for "news list"
STRTAB: Data Name
FLDS: Title Bar
COLS: Corresponding data field
STRCON: Query Conditions
PageSize: Number of display
STARTINDEX: Start page (0, 1, 2, 3)
Returns a string code, this code is the HTML code of the generated paging navigation. In the PageLoad event, the method is called, and the return value assigns a DIV to the page.
THIS.NEW_PAGE.INNNERHTML = page.pagelist (Strtertle, Strtab, FLDS, COLS, STRCON, RECORDCOUNT, PAGESIZE, 0);
Sample code: Conversion, please contact me.
MSN: fanhuayi76@hotmail.com
QQ: 7760126