Small programs constitute a major item--pagination display

Source: Internet
Author: User
Tags exit count one table
Program | pagination | show | project

Small programs constitute a major item--pagination display

Chen GENFA

For a long time did not write the article, is to feel a bit sorry myself, see my article probably not many people, so it doesn't matter right from the beginning of everyone. :)

The author recently just out of the school, full of mixed things, no worries quiet down to write things, today is free, yes, write points.

Every time I write something that tastes like a fish, but can't restrain my desire to write. Please forgive me if you hinder your view.

But the main meaning of the author is still hope that people through these fragments know me. In the career of life, technology may be the backbone, but the whole journey of life, there may be other things than technology more important! For example, for people.

I hope you predecessors pointed out the article and my shortcomings, to our younger generation point a lamp!

The topic I'm going to talk about today is very simple, how to implement a paging display in vb.net to display the specified number of records in a table control. It is the essence is from a dataset1 of the m record to remove N records exist in another Dataset2

The demand is clear, then we'll do it together.

A Create a table with the DataSet1 table (0) structure, assuming that DataSet1 has only one table.

Dim Tab1 as Datatable=dataset1. Table (0). Clone



Two Defines an object that holds the specified set of records

Dim Ary As Object

Dim I As Integer

For I=1 to N ' n is the number of records that should be fetched

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

Next



Three Update Dataset2 with Object objects

1. Update TAB1 through rows

Drow. ItemArray = ary ' drow as DataRow object

Tab1. Rows.Add (Drow)

2. Update page ' page ' for returned DataSet object via TAB1

Page. Tables.add (TAB1)



Four Back to Page

Return page

The complete code example is as follows:

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

' Name: Page class

' Features: Paging

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

Class Page

'----method, paging

' Parameters (total DataSet, current page number)



Public Function Pageset (ByVal ds as DataSet, ByVal Curpage as Integer) as DataSet

Dim I, J, R as Integer

' Dim J as Integer

Dim m as Integer = 25 ' A page how many strips

' Page J

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

' Determine if the number of pages passed in 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

' Take the qualifying m record

i = m * (curpage-1)

For each Dr in DS. Tables (0). Rows

Drow = tab. NewRow

ary = ds. Tables (0). Rows (i). ItemArray

Drow. ItemArray = ary

tab. Rows.Add (Drow)

i + 1

' There's a record of M that jumps out

If i > M * curpage-1 Then

Exit for

End If

Next

Page. Tables.add (tab)

Return page

End Function

End Class

All right, you're done, you just have to set the DataSource of your Table control to page, ok!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.