.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
結合PagedDataSource開發DataList Web應用

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

源代碼部分(.aspx.vb)


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在這裡放置使用者程式碼以初始化網頁
        If Not IsPostBack Then
            pds.DataSource = Me.CreateDataSource
            pds.AllowPaging = True
            pds.PageSize = 4
            intTotalRec = Me.CreateDataSource.Count
            pds.CurrentPageIndex = 0
            'Response.Write(" ")
            intTotalPage = pds.PageCount.ToString
            Me.DataList1.DataSource = pds
            Me.DataList1.DataBind()
            Me.showinfo()
            'Session("pc") = "1"
        Else
            '含有Session的注釋代碼表示在頁面驅動了一個事件後
            '會先執行page_load事件然後執行所對應的的事件.
            'Session("pc") = Session("pc") + "2" 
            'Response.Write(" ")
            pds.DataSource = Me.CreateDataSource
            pds.AllowPaging = True
            pds.PageSize = 4
            intTotalRec = Me.CreateDataSource.Count
            'Response.Write(" ")
            intTotalPage = pds.PageCount.ToString
        End If
    End Sub

    Public Function CreateDataSource() As DataView
        Dim dt As DataTable
        Dim dr As DataRow

        dt = New DataTable
        dt.Columns.Add("Integer", GetType(Integer))
        dt.Columns.Add("String", GetType(String))

        Dim i As Integer
        For i = 0 To 5
            dr = dt.NewRow
            dr.Item(0) = i
            dr.Item(1) = "item " & i.ToString
            dt.Rows.Add(dr)
        Next

        CreateDataSource = dt.DefaultView
    End Function

    Private Sub lbFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbFirst.Click
        'Session("pc") = Session("pc") + "3"
        'Response.Write(" ")

        pds.CurrentPageIndex = 0
        Me.DataList1.DataSource = pds
        Me.DataList1.DataBind()
        Me.showinfo()
    End Sub

    Private Sub lbLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbLast.Click
        pds.CurrentPageIndex = Me.intTotalPage - 1
        Me.DataList1.DataSource = pds
        Me.DataList1.DataBind()
        Me.showinfo()
    End Sub

    Private Sub lbPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbPrevious.Click
        If pds.CurrentPageIndex = 0 Then
        Else
            pds.CurrentPageIndex -= 1
        End If
        Me.DataList1.DataSource = pds
        Me.DataList1.DataBind()
        Me.showinfo()
    End Sub

    Private Sub lbNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbNext.Click
        If pds.CurrentPageIndex = pds.PageCount - 1 Then
        Else
            pds.CurrentPageIndex += 1
        End If
        Me.DataList1.DataSource = pds
        Me.DataList1.DataBind()
        Me.showinfo()
    End Sub

    Private Sub showinfo()
        Me.lInfo.Text = (pds.CurrentPageIndex + 1).ToString & "/" & Me.intTotalPage.ToString
    End Sub


Note:

需要給PagedDataSource賦一個數據源,同時還要設定允許分頁(AllowPaging)、每頁的大小(PageSize),這樣PagedDataSource對象就可以自動算出頁數(PageCount),然後就可以把這個PagedDataSource作為數據源賦於一個DataList對象,最後將DataList對象綁定。




相关文章

相关软件