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

推荐订阅源

J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
L
LangChain Blog
C
Check Point Blog
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
Recent Announcements
Recent Announcements
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
U
Unit 42
The Cloudflare Blog
月光博客
月光博客
有赞技术团队
有赞技术团队
G
Google Developers Blog
Vercel News
Vercel News

博客园 - 生活即技术

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

刷新页面返回顶部