09/10/2018, 22:47
kỹ thuật phân trang trong ASP
Em đang mắc cái vụ này lắm đó
bác nào biết chỉ dùm thằng em này đi
mong các bác cho thằng em này một đoạn code để hiểu dễ dàng hơn
cảm ơn các bác nhiều
bác nào biết chỉ dùm thằng em này đi
mong các bác cho thằng em này một đoạn code để hiểu dễ dàng hơn
cảm ơn các bác nhiều
Bài liên quan
Making use of the Page properties. This example shows how to display only records on a selected page at a time. This is useful when dealing with large data sources.
[VB]
'clear list
lstTreeList.Items.Clear()
'move to selected page
rsTrees.AbsolutePage = thispage
'loop while still on selected page
While rsTrees.AbsolutePage = thispage
'create new listview item with tree index as text value
Dim lviNewItem As System.Windows.Forms.ListViewItem _
= New ListViewItem(rsTrees.Fields(0).Value.ToString())
'add tree name as sub-item
lviNewItem.SubItems.Add(rsTrees.Fields(1).Value.To String())
'add tree height as sub-item formatted with two fixed decimal places
lviNewItem.SubItems.Add(Format(rsTrees.Fields(2).V alue, "F"))
'add the item to the list
lstTreeList.Items.Add(lviNewItem)
'move to the next record
rsTrees.MoveNext()
End While
Bạn không cần phải dùng các thuật toán khác.
Thế này nhé:
Bạn dùng Recordset.PageSize và Recordset.RecordCount để phân trang
Ví dụ
Recordset.RecordCount là 50 (thuộc tính chỉ đọc)
Recordset.Pagesize = 10
Nghĩa là bạn đang chia nhỏ Recordset thành 5 trang, mỗi trang 10 Records
Sau đó bạn xài Recordset.AbsolutePage = 1,2,3,4,5 để nhảy tới các trang cần lấy dữ liệu.
Ví dụ:
Recordset.AbsolutePage =2
Do while not Recordset.EOF
' xu ly data tren tung record
Recordset.MoveNext
Loop
=> bạn đang xử lý trên Records thứ 6 đến 10, trang thứ 2 của Recordset
Và cuối cùng là thuộc tính RecordSet.AbsolutePosition cho bạn biết bạn đang ở Record nào trong toàn bộ Recordset
Sau khi bạn load Resultset vào 1 mảng. Bạn có thể tùy ý phân trang.
Ví dụ Kích thước mảng là 50 item
Bạn có thể xài biến phụ trợ:
iRecordCout = 50
iPageSize = 10
=> vậy số trang sẽ là
iPageCount = iRecordCount / iPageSize (bằng 5)
sau đó:
iAbsolutePage = 1, 2, 3, 4, 5, .... để duyện trang
và dùng iAbsoluteRecord để định vị từng record đang xử lý
-------------------------------------------------------------------------------
Có ai có cách khác không, cùng thảo luận
Phân trang dữ liệu với ASP và ADODB
em sẽ thử xem có gì khó em lại hỏi tiếp
thank every one