The GridView control provides you with an easy way to display the number of items on a page without taking much space with the help of paging. For Example you have a record set of 500 items and you want to display 10 items per page using paging.
Drag and drop a GridView control on the form.
ASPX code
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
onrowdatabound="GridView1_RowDataBound" PageSize="5">
<PagerTemplate>
<asp:Menu ID="Menu1" runat="server" onmenuitemclick="Menu1_MenuItemClick"
Orientation="Horizontal">
</asp:Menu>
<asp:LinkButton ID="btnNext" runat="server" CommandName="Next"
oncommand="Navigate">></asp:LinkButton>
</PagerTemplate>
</asp:GridView>
GridView control looks like below image.
Figure1
Now double click on the form and add the following code.
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) HandlesMe.Load
If Not Page.IsPostBack Then
binding()
End If
End Sub
Private Sub binding()
Dim tblData As New DataTable()
Dim col1 As New DataColumn("Data1")
tblData.Columns.Add(col1)
For i As Integer = 1 To 1500
Dim dr As DataRow = tblData.NewRow()
dr("Data1") = i
tblData.Rows.Add(dr)
Next
GridView1.DataSource = tblData
GridView1.DataBind()
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e AsGridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.Pager Then
Dim pgmenu As Menu = DirectCast(e.Row.FindControl("Menu1"), Menu)
Dim startno As Integer, endno As Integer
Dim selectedpgeno As Integer = -1
If ViewState("selectedpgno") Is Nothing Then
startno = 1
endno = startno + 10
Else
selectedpgeno = Convert.ToInt32(ViewState("selectedpgno"))
If (selectedpgeno - 10) <= 0 Then
startno = 1
endno = selectedpgeno + 9
Else
startno = selectedpgeno - 10
endno = selectedpgeno + 9
End If
End If
For i As Integer = startno To endno
pgmenu.Items.Add(New MenuItem(i.ToString(), (i - 1).ToString()))
Next
End If
End Sub
Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
ViewState.Add("selectedpgno", e.Item.Text)
GridView1.PageIndex = Convert.ToInt32(e.Item.Value)
binding()
End Sub
Protected Sub Navigate(ByVal sender As Object, ByVal e As CommandEventArgs)
If e.CommandName = "Next" Then
ViewState.Add("selectedpgno", GridView1.PageIndex + 1)
GridView1.PageIndex = Convert.ToInt32(GridView1.PageIndex + 1)
binding()
End If
End Sub
End Class
Now run the application and test it.
Figure2
Now click on the paging number 2 to show next five record.

Figure3