- // Default.aspx
- <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>GridView Paging Example</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:GridView ID="Contacts" runat="server" AllowPaging="true" OnPageIndexChanging="PageIndexChanging" />
- </div>
- </form>
- </body>
- </html>
- // Default.aspx.vb
- Imports System.Data
- Imports System.Data.SqlClient
- Partial Class _Default
- Inherits System.Web.UI.Page
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
- Me.BindGridView()
- End Sub
- Private Sub BindGridView()
- Dim provider As String = "Data Source=;Initial Catalog=AdventureWorks;Integrated Security=True"
- Dim con As New SqlConnection(provider)
- Try
- con.Open()
- Dim cmd As New SqlCommand("SELECT FirstName, MiddleName, LastName, EmailAddress FROM Person.Contact", con)
- Dim table As New DataTable()
- Dim adapter As New SqlDataAdapter(cmd)
- adapter.Fill(table)
- Contacts.DataSource = table
- Contacts.DataBind()
- Catch ex As Exception
- Response.Write(ex.Message)
- End Try
- End Sub
- Protected Sub PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
- Contacts.PageIndex = e.NewPageIndex
- Contacts.DataBind()
- End Sub
- End Class
ASP.Net - VB - GridView Paging Example
The following code snippet demonstrates how to apply paging to a GridViewcontrol using the PageIndexChanging event.
No comments:
Post a Comment