Small program constitutes a big project - page display

zhaozj2021-02-16  51

Small program constitutes a big project - page display

Chen Genfa

I haven't written the article for a long time, I feel a bit sorry, seeing the people in my article, there is nothing to do with everyone. :)

The author recently came out of the school gate, full of brains, no heart, quiet, there is no time, nice, good, write some.

Every time I wrote something a bit of the taste of the door, but I can't restrain my desire to write. If you happen, please forgive me.

However, the main meaning of the author still hopes that everyone will know me through these words. In the career of life, technology may be a backbone, but in the entire trip to life, there may be more important things than technology! For example, for people.

I hope that the seniors point out the article and my life, give us a light!

The topic I have to say today is simple, how to implement pagination display in VB.NET to display the specified number of records in the table control. It is essentially from the M string record in a DataSet1 to remove the N records in another DataSet2

Demand is clear, let's go together.

One. Building a Table with DataSet1, assuming that DataSet1 has only one table.

Dim tab1 as datatable = dataset1. Table (0) .clone

two. Define an Object object to store the specified recordset

DIM ARY As Object

DIM I as integer

For i = 1 to n 'N is the number of records that should be taken out

Ary = dataset1. Table (0) .Rows.ItemRay (i)

NEXT

three. Update DataSet2 with Object Objects

1. Update Tab1 via ROWS

DROW.ITEMARRAY = ary 'drow for the DataRow object

Tab1.Rows.Add (DROW)

2. Update by Tab1 Page 'Page is the DataSet object returned

Page.Tables.Add (Tab1)

four. Return to Page

Return Page

The complete code example is, for example:

'================================

'Name: Page class

'Features: Page

'============================================================================================================================================================

Class Page

'---- Method, Page

'Parameter (DataSet total, current page number)

Public Function Pageset (byval ds as dataset) AS Dataset

DIM I, J, R AS INTEGER

'DIM J AS INTEGER

DIM m as integer = 25 'how many

'Number of pages

J = CINT (DS.TABLES (0) .Rows.count / M 0.5) DIM Page As New DataSet

DIM TAB AS DATATABLE

Tab = ds.tables (0) .clone

DIM DR AS DATAROW

DIM COL AS Datacolumn

DIM DROW AS DATAROW

'DIM R AS Integer = 0

DIM ary () as object

'Judging whether the number of incoming pages is reasonable

If DS.TABLES (0) .Rows.count <= 0 THEN

EXIT FUNCTION

END IF

IF Curpage <1 THEN

CURPAGE = 1

Elseif Curpage> j Then

CURPAGE = J

END IF

'Record the requirements of the requirements

i = m * (CURPAGE - 1)

For Each Dr in Ds.Tables (0). ROWS

DROW = Tab.newrow

Ary = ds.tables (0) .ROWS (i) .ITEMARRAY

Drow.ItemRay = ary

Tab.Rows.Add (DROW)

i = 1

'There is a record of M sticks

IF i> M * Curpage - 1 THEN

EXIT for

END IF

NEXT

Page.Tables.Add (Tab)

Return Page

END FUNCTION

END CLASS

Ok, I am very good, you just want to set your table control DataSource to Page, OK!

-------------------------------------------------- -----------------

转载请注明原文地址:https://www.9cbs.com/read-22185.html

New Post(0)