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

推荐订阅源

博客园 - 三生石上(FineUI控件)
G
Google Developers Blog
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Engineering at Meta
Engineering at Meta
B
Blog
博客园_首页
量子位
博客园 - 叶小钗
L
LangChain Blog
T
The Blog of Author Tim Ferriss
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
F
Fortinet All Blogs
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
D
DataBreaches.Net
雷峰网
雷峰网
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
TaoSecurity Blog
TaoSecurity Blog
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
I
Intezer
H
Help Net Security
The Hacker News
The Hacker News
The Register - Security
The Register - Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
AWS News Blog
AWS News Blog
V
V2EX
Microsoft Security Blog
Microsoft Security Blog
T
Tenable Blog
Spread Privacy
Spread Privacy
A
Arctic Wolf
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
Schneier on Security
Schneier on Security
C
CERT Recently Published Vulnerability Notes
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Last Watchdog
The Last Watchdog
Latest news
Latest news
T
Troy Hunt's Blog
L
LINUX DO - 热门话题

博客园 - 生活即技术

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

Posted on 2004-11-15 16:18  生活即技术  阅读(427)  评论(0)    收藏  举报

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="Data.WebForm1"%>
<HTML>
    
<body>
        
<form runat="server">
            
For our recordcount and pagecount
            
<asp:Label id="lblPageCount" runat="server" /><br>
            
<asp:DataGrid id="Data1" AllowPaging="True" OnPageIndexChanged="DataGrid_PageIndex" AutoGenerateColumns="False"
                runat="server" Width="536px">
                
<Columns>
                
<asp:BoundColumn DataField="id"></asp:BoundColumn>
                
<asp:HyperLinkColumn   DataNavigateUrlFormatString="aspx?id={0}" DataNavigateUrlField="uname" DataTextField="uname"  HeaderText="用户名" ></asp:HyperLinkColumn>
                
</Columns>
                
<PagerStyle  Width="100%"  NextPageText="下一页 " PrevPageText="上一页" PageButtonCount="5" Mode="NumericPages"></PagerStyle>
            
</asp:DataGrid>
            
        
</form>
    
</body>
</HTML>

后台代码

Public Class WebForm1
    
Inherits System.Web.UI.Page

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

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

    
End Sub

    
Protected WithEvents lblPageCount As System.Web.UI.WebControls.Label
    
Protected WithEvents Pubs As System.Web.UI.WebControls.DataGrid
    
Protected WithEvents ps As System.Web.UI.WebControls.DropDownList
    
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    
Protected WithEvents Data1 As System.Web.UI.WebControls.DataGrid

    
'注意: 以下占位符声明是 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
    
Dim totalcount As Int32
    
Private Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load
        
'在此处放置初始化页的用户代码
        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 top 100 id,uname  from user_login "
        Try
            Myconnection 
= New SqlClient.SqlConnection(connstr)
            Myconnection.Open()
            MyAdatper 
= New SqlClient.SqlDataAdapter(sql, Myconnection)
            MyAdatper.Fill(ds, 
"User_login")
            totalcount 
= ds.Tables("user_login").Rows.Count.ToString
            lblPageCount.Text 
= totalcount
            Data1.DataSource 
= ds.Tables("user_login")
            Data1.DataBind()
        
Catch ecc As Exception
            Response.
Write(ecc.Message)
            Response.
End()
        
Finally
        
End Try
        Response.
Write("连接成功")
    
End Sub

    
Sub DataGrid_PageIndex(ByVal sender As ObjectByVal e As DataGridPageChangedEventArgs)
        Data1.CurrentPageIndex 
= e.NewPageIndex
    
End Sub

End Class

刷新页面返回顶部