惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
A
About on SuperTechFans
GbyAI
GbyAI
宝玉的分享
宝玉的分享
爱范儿
爱范儿
博客园 - 【当耐特】
博客园 - 司徒正美
博客园 - 聂微东
P
Proofpoint News Feed
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
B
Blog RSS Feed
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
J
Java Code Geeks
博客园 - 叶小钗

博客园 - 生活即技术

好久不更新了,忙的惭愧哦,思考一个应用 利用dataTable 排序的解决方法 项目中遇到的一些小问题及解决方法 常用代码 一个com+消息队列的例子 部署Com+ 2004我的爱,2005我的期待 加密解密相关 生成略缩图 论坛在线人数统计代码 上礼拜六犯的愚蠢错误 正则表达式(1) 又一新的分页方法(转帖) 用户控件的使用(二) 用户控件的使用(一) DataList的使用(1) DataGrid的使用(2)自定义分页 DataGrid的使用(1)
DataList的使用(二)自定义分页的实现
生活即技术 · 2004-11-16 · via 博客园 - 生活即技术

Datalist_page.aspx页

Datalist_page.aspx.vb页

Public Class DataList_Page
    
Inherits System.Web.UI.Page

#Region 
" Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    
End Sub

    
Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList
    
Protected WithEvents frist As System.Web.UI.WebControls.LinkButton
    
Protected WithEvents prePage As System.Web.UI.WebControls.LinkButton
    
Protected WithEvents nextPage As System.Web.UI.WebControls.LinkButton
    
Protected WithEvents lastPage As System.Web.UI.WebControls.LinkButton
    
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    
Protected WithEvents CurrenPage_ As System.Web.UI.HtmlControls.HtmlInputHidden
    
Protected WithEvents Current_ As System.Web.UI.HtmlControls.HtmlInputHidden

    
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    
Private Sub Page_Init(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Init
        
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    
End Sub


#
End Region
    
Const Pagesize As Integer = 10
    
Public Totalpage As Int32
    
Dim CurrentPage As Int32
    
Dim TotalCount As Integer
    
Private Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load
        
'在此处放置初始化页的用户代码
        If Not IsPostBack Then
            DataList1.DataSource 
= Databind_(0)
            DataList1.DataBind()
            Totalpage 
= GetTotalPage()
            Label1.Text 
= "当前页:1/" & Totalpage
            Current_.Value 
= 1
        
End If
    
End Sub

    
Function Databind_(ByVal StartIndex) As System.Data.DataTable
        
Dim Sqlstr As String = "server=(local);database=Achem56;uid=sa;pwd= "
        Dim Sql As String = "select   id,uname from user_login  "
        Dim Sqlconn As New System.Data.SqlClient.SqlConnection(Sqlstr)
        
Dim Sqlcmd As New System.Data.SqlClient.SqlDataAdapter(Sql, Sqlconn)
        
Dim SqlDataSet As New DataSet
        Sqlcmd.Fill(SqlDataSet, StartIndex, Pagesize, 
"user_login")
        
Return SqlDataSet.Tables("user_login")
    
End Function

    
Function GetTotalPage() As Int64                     '取得总页数
        Dim Sqlstr As String = "server=(local);database=Achem56;uid=tiantian;pwd=tiantian "
        Dim Sql As String = "select   id,uname from user_login order by id desc "
        Dim Sqlconn As New System.Data.SqlClient.SqlConnection(Sqlstr)
        Sqlconn.Open()
        
Dim Sqlcommand As New System.Data.SqlClient.SqlCommand
        Sqlcommand.CommandText 
= "select count(id) from user_login "
        Sqlcommand.Connection = Sqlconn
        TotalCount 
= Sqlcommand.ExecuteScalar
        Sqlconn.Close()
        
If TotalCount Mod Pagesize <> 0 Then
            GetTotalPage 
= TotalCount \ Pagesize + 1
        
Else
            GetTotalPage 
= TotalCount \ Pagesize
        
End If
    
End Function

    
Sub PagerButtonClick(ByVal send As ObjectByVal e As CommandEventArgs)   '上一页,下一页,首页,尾页的处理
        Dim Current_Page As Int32 = CInt(Current_.Value)
        Totalpage 
= GetTotalPage()
        
Select Case e.CommandArgument
            
Case "Frist"
                DataList1.DataSource = Databind_(0)
                DataList1.DataBind()
                Label1.Text 
= "当前页:1 / " & Totalpage
                Current_.Value 
= 1
            
Case "pre"
                If Current_Page > 1 Then
                    Current_Page 
= Current_Page - 1
                    Label1.Text 
= "当前页:" & Current_Page & "/" & Totalpage
                    DataList1.DataSource 
= Databind_((Current_Page - 1* Pagesize)
                    DataList1.DataBind()
                    Current_.Value 
= Current_Page.ToString
                
End If
            
Case "next"
                If Current_Page < Totalpage Then
                    Current_Page 
= Current_Page + 1
                    Label1.Text 
= "当前页:" & Current_Page & "/" & Totalpage
                    DataList1.DataSource 
= Databind_((Current_Page - 1* Pagesize)
                    DataList1.DataBind()
                    Current_.Value 
= Current_Page.ToString
                
End If
            
Case "last"
                Label1.Text = "当前页:" & Totalpage & "/" & Totalpage
                DataList1.DataSource 
= Databind_((Totalpage - 1* Pagesize)
                DataList1.DataBind()
                Current_.Value 
= Totalpage
        
End Select
    
End Sub

End Class

 今天终于实现了DataGrid、DataList的自定义分页,其实Reapeater实现的方法是一样的。
关键是adapter.fill(ds,StartRecord,size,"表名")
StartRecord 是开始的记录号。计算方法是 (页数-1)*页的大小
size 是每页的大小