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

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
Hacker News: Ask HN
Hacker News: Ask HN
T
Threatpost
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
S
SegmentFault 最新的问题
月光博客
月光博客
Latest news
Latest news
博客园 - Franky
T
Threat Research - Cisco Blogs
有赞技术团队
有赞技术团队
博客园_首页
T
The Exploit Database - CXSecurity.com
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
C
Cybersecurity and Infrastructure Security Agency CISA
S
Schneier on Security
Simon Willison's Weblog
Simon Willison's Weblog
爱范儿
爱范儿
Security Latest
Security Latest
Scott Helme
Scott Helme
博客园 - 聂微东
T
Tor Project blog
美团技术团队
IT之家
IT之家
Stack Overflow Blog
Stack Overflow Blog
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
G
Google Developers Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
AWS News Blog
AWS News Blog
Jina AI
Jina AI
Vercel News
Vercel News
小众软件
小众软件
T
Tenable Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Forbes - Security
Forbes - Security
aimingoo的专栏
aimingoo的专栏
O
OpenAI News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
AI
AI

博客园 - 生活即技术

好久不更新了,忙的惭愧哦,思考一个应用 利用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 是每页的大小