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

推荐订阅源

美团技术团队
P
Privacy International News Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
C
CXSECURITY Database RSS Feed - CXSecurity.com
Know Your Adversary
Know Your Adversary
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Attack and Defense Labs
Attack and Defense Labs
NISL@THU
NISL@THU
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
GbyAI
GbyAI
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Y
Y Combinator Blog
C
CERT Recently Published Vulnerability Notes
N
Netflix TechBlog - Medium
S
Security Affairs
Spread Privacy
Spread Privacy
罗磊的独立博客
腾讯CDC
MyScale Blog
MyScale Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
L
LINUX DO - 热门话题
The Cloudflare Blog
L
LangChain Blog
博客园_首页
H
Hacker News: Front Page
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
博客园 - 聂微东
SecWiki News
SecWiki News
A
Arctic Wolf
爱范儿
爱范儿
Google Online Security Blog
Google Online Security Blog
T
Threat Research - Cisco Blogs
Hacker News - Newest:
Hacker News - Newest: "LLM"
有赞技术团队
有赞技术团队
The GitHub Blog
The GitHub Blog
Cyberwarzone
Cyberwarzone
博客园 - 叶小钗
V
Visual Studio Blog
V
V2EX
T
Tailwind CSS Blog
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
MongoDB | Blog
MongoDB | Blog
D
Docker

博客园 - 生活即技术

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

DataGrid.aspx页

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="DataGrid_page.aspx.vb" Inherits="Data.DataGrid_page"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    
<HEAD>
        
<title>DataGrid_page</title>
        
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
        
<meta name="vs_defaultClientScript" content="JavaScript">
        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    
</HEAD>
    
<body>
        
<form id="Form1" method="post" runat="server">
            
<table>
                
<tr>
                    
<td style="HEIGHT: 5px">
                        
<asp:DataGrid id="DataGrid1" AllowCustomPaging="false" PageSize="10" DataKeyField="id" AllowPaging="True"
                            AutoGenerateColumns="False" runat="server" Width="504px">
                            
<Columns>
                                
<asp:TemplateColumn  HeaderText="编号"  > 
                                
<ItemTemplate ><b><a  href='<%# DataBinder.Eval(Container.DataItem, "id","aspx?id={0}") %>'>编号</a></b></ItemTemplate>
                                </asp:TemplateColumn> 
                                
<asp:BoundColumn DataField="uname" HeaderText="用户名"></asp:BoundColumn>
                            
</Columns>
                            
<PagerStyle Visible="False"></PagerStyle>
                        
</asp:DataGrid>
                    
</td>
                
</tr>
                
<tr>
                    
<td>
                        
<table width="500">
                            
<tr>
                                
<td>
                                    
<asp:linkbutton Runat="server" ID="frist" OnCommand="PagerButtonClick" CommandArgument="Frist">首页</asp:linkbutton>
                                    
<asp:linkbutton Runat="server" ID="prePage" OnCommand="PagerButtonClick" CommandArgument="pre">上一页</asp:linkbutton>
                                    
<asp:linkbutton Runat="server" ID="nextPage" OnCommand="PagerButtonClick" CommandArgument="next">下一页</asp:linkbutton>
                                    
<asp:linkbutton Runat="server" ID="lastPage" OnCommand="PagerButtonClick" CommandArgument="last">尾页</asp:linkbutton>
                                
</td>
                            
</tr>
                        
</table>
                    
</td>
                
</tr>
            
</table>
        
</form>
    
</body>
</HTML>

DataGrid.aspx.vb页

Public Class DataGrid_page
    
Inherits System.Web.UI.Page

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

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

    
End Sub

    
Protected WithEvents Data As System.Web.UI.WebControls.DataGrid
    
Protected WithEvents a As System.Web.UI.WebControls.DataGrid
    
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    
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

    
'注意: 以下占位符声明是 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

    
Private Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load
        
'在此处放置初始化页的用户代码
        If Not IsPostBack Then
            DataBlind()
        
End If
    
End Sub


    
Sub DataBlind()
        
Dim Myconnection As SqlClient.SqlConnection
        
Dim MyAdatper As SqlClient.SqlDataAdapter
        
Dim ds As New DataSet
        
Dim read As SqlClient.SqlDataReader
        
Dim connstr = "server=(local);uid=sa;pwd=;database=achem56;"
        Dim sql As String = "select  id,uname  from user_login "
        Try
            Myconnection 
= New SqlClient.SqlConnection(connstr)
            MyAdatper 
= New SqlClient.SqlDataAdapter(sql, Myconnection)
            MyAdatper.Fill(ds, 
"User_login")
            DataGrid1.DataSource 
= ds.Tables("user_login")
            DataGrid1.DataBind()
        
Catch ecc As Exception
            Response.
Write(ecc.Message)
            Response.
End()
        
Finally
        
End Try
        Response.
Write("CurrentPageindex/totalPageIndex: " & DataGrid1.CurrentPageIndex + 1 & "/" & DataGrid1.PageCount)
    
End Sub

    
Sub PagerButtonClick(ByVal sender As ObjectByVal e As CommandEventArgs)
        
Select Case e.CommandArgument
            
Case "Frist"
                DataGrid1.CurrentPageIndex = 0
            
Case "pre"
                If DataGrid1.CurrentPageIndex > 0 Then
                    DataGrid1.CurrentPageIndex 
= DataGrid1.CurrentPageIndex - 1
                
End If
            
Case "next"
                If DataGrid1.CurrentPageIndex < DataGrid1.PageCount - 1 Then
                    DataGrid1.CurrentPageIndex 
= DataGrid1.CurrentPageIndex + 1
                
End If
            
Case "last"
                DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1
        
End Select
        DataBlind()
    
End Sub


    
Private Sub DataGrid1_PageIndexChanged(ByVal source As ObjectByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        DataGrid1.CurrentPageIndex 
= e.NewPageIndex
        DataBlind()
    
End Sub

End Class

代码其实是不复杂的,重点是理解DataGrid的处理过程,事件机制.