Berikut adalah contoh Paginasi pada DataGridView dengan Visual Basic .Net
Buat tampilan seperti gambar diatas terdiri dari 2 Button, dengan nama masing-masing btnPrev, btnNext lalu 1 DataGridView
Setelah itu tambahkan sintak seperti dibawah ini :
Imports System.Data.SqlClient
Public Class Form1
Dim pagingAdapter As SqlDataAdapterDim pagingDS As DataSetDim scrollVal As IntegerPrivate Const dtbase As String
dtbase = “data source=.;initial catalog=lp3i;integrated security=true”
Private Sub viewData()
Dim sql As String = “Select * From barang”Dim connection As New SqlConnection(dtbase)pagingAdapter = New SqlDataAdapter(sql, connection)pagingDS = New DataSet()connection.Open()pagingAdapter.Fill(pagingDS, scrollVal, 10, “isiTabel”)connection.Close()DataGridView1.DataSource = pagingDSDataGridView1.DataMember = “isiTabel”
End SubPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
viewData()
End SubPrivate Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
scrollVal = scrollVal – 10If scrollVal <= 0 ThenscrollVal = 0End IfpagingDS.Clear()pagingAdapter.Fill(pagingDS, scrollVal, 10, “isiTabel”)
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
scrollVal = scrollVal + 10If scrollVal > 23 Then
scrollVal = 28
End IfpagingDS.Clear()pagingAdapter.Fill(pagingDS, scrollVal, 10, “isiTabel”)
End Sub
End Class
Jalankan tekan F5