제목 : 8. 출력 페이지 클래스 작성(List.aspx.vb) 업그레이드(페이징 처리)
Imports System.Data
Imports System.Data.SqlClient
Public Class List
Inherits System.Web.UI.Page
#Region " Web Form 디자이너에서 생성한 코드 "
'이 호출은 Web Form 디자이너에 필요합니다.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
'참고: 다음의 자리 표시자 선언은 Web Form 디자이너의 필수 선언입니다.
'삭제하거나 옮기지 마십시오.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 이 메서드 호출은 Web Form 디자이너에 필요합니다.
'코드 편집기를 사용하여 수정하지 마십시오.
InitializeComponent()
End Sub
#End Region
Dim intPage As Integer = 0
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.PageSize = 5
Listing()
End If
End Sub
Private Sub Listing()
Dim objCon As SqlConnection
Dim objCmd As SqlCommand
objCon = New SqlConnection("server=localhost;user id=dotnetnote;password=dotnetnote;database=dotnetnote")
objCon.Open()
objCmd = New SqlCommand("Select Num, Title, Name, PostDate, ReadCount From DotnetNoteBasicVB" & _
" Order By Num Desc", objCon)
Dim objDa As SqlDataAdapter = New SqlDataAdapter
objDa.SelectCommand = objCmd
Dim objDs As DataSet = New DataSet
objDa.Fill(objDs, "DotnetNoteBasicVB")
DataGrid1.DataSource = objDs.Tables("DotnetNoteBasicVB").DefaultView
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
Listing()
End Sub
End Class