Attribute
Allowsorting:Allow paging?
Pagesize:Page size
Currentpageindex:Current page,CurrentpageindexIt should be greater than or equal to 0 and less than or equalPagecount
Pagecount:Page number
Virtualitemcount:The DataGrid needs to calculate the number of pages based on the number of records, but the custom paging mode does not need to obtain all records at a time, so it needs to be explicitly setVirtualitemcountAssignment
Event
Pageindexchanged:ChangePageindex. InPageindexchangedUpdatingCurrentpageindexAttribute and re-bind datasource (Be sure to re-bind datasource. If datasource is not re-bound, the DataGrid will use viewstate Information)
Customization
UseDatagridpagerstyleClass or To control the display
IncludingBackcolor; font; forecolor; horizontalalign; mode; nextpagetext; prevpagetext; pagebuttoncount; position; Width
If you want to customize the navigation bar, such as 1, 2 --> [1], [2]OnitemcreatedIn the event, the page navigation bar of the DataGrid is a tablerow object that contains a tablecell object that spans all columns. To access the pagination button, you need to traverse the controls set of tablerow, (spaces between paging buttons are also controls, and the time can be skipped)
To implement a more complex navigation bar, you canVisibleSet property to false, and then add your own navigation bar. The custom navigation bar can be independent from the DataGrid.
More complex customization can be performed onOnitemcreatedEvent.
Default paging Mode
SetAllowsortingTrue, only displayPagesizeReocrd size
If the DataGrid uses default paging in paging mode, datasource must be an object that implements the icollection interface, because the DataGrid needs to know the number of records of the datasouce object (Dataset implements the icollection interface but datareader does not ).
In default paging mode, all data is accepted, but only part of the data is displayed.
Custom paging Mode
If the DataGrid paging mode uses M paging, datasource does not need to implement icollection, so datareader can be used.
ObtainVirtualitemcountYou can use executescalar and executescalar to execute a query. Only the first column of the First row in the returned result set is returned.
To calculate the number of records in the datasource for a reocrd, you can use a temporary table containing an incremental field (for example, increasingid int identity () in the stored procedure, however, this method is not applicable when the data volume is very large.
For tables with an incremental Integer as the primary key, you can save the maximum primary key of the smallest primary key on each page, and then implement paging by combining select top and order by (note the order of order, determine whether to use DESC or ASC based on the previous page or the next page. However, this method does not apply to mode = "numericpages"
Or use set rowcount XXXX instead of select top, but do not forget to call set rowcount 0 at last.
Or sort the primarykey of datasource and save it to arraylist.Pagesize, currentpageindex, newpageindexCalculate the primarykey range of this page, and use join and getrange to make up the primarykey in the range into a string, passed in the Stored Procedure select... from... where... and primarykeycolumn in (...). With the help of index, primarykey operations should be very fast.
Alternatively, you can use nested select top statements, such as N records per page. To view page M, you can
Select top * from (
Select Top N * from
(Select Top N * m * From table_name order by primarykey)
Order by primarykey DESC
) Order by primarykey
Honestly, this method is stupid.
Another quick method is to use the database cursor. The example is as follows:
Declare @ pagesize int
Declare @ page int
Declare @ total int
Declare @ start int
Declare @ end int
Declare @ maxid int
Declare @ minid int
Set @ pagesize = 10
Set @ page = 0 -- page starts from 0
Select @ start = @ page * @ pagesize + 1
Select @ end = @ start + @ pagesize-1
Declare pagecursor cursor scroll
Select contact_id from table_contact order by contact_id
Open pagecursor
Set @ Total = @ cursor_rows
Fetch absolute @ start from pagecursor into @ minid
If @ end> @ total
Fetch last from pagecursor into @ maxid
Else
Fetch absolute @ end from pagecursor into @ maxid
Close pagecursor
Deallocate pagecursor
Select contact_id, contact_firstname, contact_lastname
From table_contact
Where contact_id between @ minid and @ maxid
Order by contact_id
The pageddatasource class can be used for controls that do not support paging.