WebForm1.aspx页面
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="xinjie.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</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 MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DataGrid id="DataGrid" style="Z-INDEX: 101; LEFT: 152px; POSITION: absolute; TOP: 40px" runat="server"
Width="296px" Height="224px" AllowCustomPaging="True" AllowPaging="True" AutoGenerateColumns="True"
OnPageIndexChanged="DataGrid_SelectedIndexChanged" PageSize="20" CellPadding="2" CellSpacing="2"
HorizontalAlign="Center" DataKeyField="id" BackColor="#FFFFC0" BorderColor="#C0FFFF" BorderStyle="Outset"
ForeColor="#8080FF" ShowFooter="True" AllowSorting="True" EnableViewState="False">
<SelectedItemStyle BorderColor="#FFC0C0" BackColor="Red"></SelectedItemStyle>
<PagerStyle NextPageText="下一页" PrevPageText="上一页" Position="TopAndBottom"></PagerStyle>
</asp:DataGrid></FONT>
</form>
</body>
</HTML>Public Class WebForm1
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Conn = New System.Data.SqlClient.SqlConnection
Me.Objcmd = New System.Data.SqlClient.SqlCommand
'
'Conn
'
Me.Conn.ConnectionString = "workstation id=LXYZW;packet size=4096;user id=sa;integrated security=SSPI;data so" & _
"urce=""LXYZW\LXYZW"";persist security info=False;initial catalog=lxy_zhouwei"
'
'Objcmd
'
Me.Objcmd.Connection = Me.Conn End Sub
Protected WithEvents Conn As System.Data.SqlClient.SqlConnection
Protected WithEvents Objcmd As System.Data.SqlClient.SqlCommand
Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid '注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not IsPostBack Then
Conn.Open() Objcmd.CommandText = "select id ,stu_num,stu_num,stu_profession from users" Dim Obj_reader As SqlClient.SqlDataReader = Objcmd.ExecuteReader
DataGrid.DataSource = Obj_reader
DataGrid.DataBind() End If
End Sub Sub DataGrid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As DataGridPageChangedEventArgs) Handles DataGrid.PageIndexChanged
DataGrid.CurrentPageIndex = e.NewPageIndex
Conn.Open() Objcmd.CommandText = "select id,stu_num,stu_num,stu_profession from users" Dim Obj_reader As SqlClient.SqlDataReader = Objcmd.ExecuteReader
DataGrid.DataSource = Obj_reader
DataGrid.DataBind()
End Sub
End Class
那个分页显示出来拉,但是不能点击。是怎么回事啊?
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="xinjie.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</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 MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DataGrid id="DataGrid" style="Z-INDEX: 101; LEFT: 152px; POSITION: absolute; TOP: 40px" runat="server"
Width="296px" Height="224px" AllowCustomPaging="True" AllowPaging="True" AutoGenerateColumns="True"
OnPageIndexChanged="DataGrid_SelectedIndexChanged" PageSize="20" CellPadding="2" CellSpacing="2"
HorizontalAlign="Center" DataKeyField="id" BackColor="#FFFFC0" BorderColor="#C0FFFF" BorderStyle="Outset"
ForeColor="#8080FF" ShowFooter="True" AllowSorting="True" EnableViewState="False">
<SelectedItemStyle BorderColor="#FFC0C0" BackColor="Red"></SelectedItemStyle>
<PagerStyle NextPageText="下一页" PrevPageText="上一页" Position="TopAndBottom"></PagerStyle>
</asp:DataGrid></FONT>
</form>
</body>
</HTML>Public Class WebForm1
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Conn = New System.Data.SqlClient.SqlConnection
Me.Objcmd = New System.Data.SqlClient.SqlCommand
'
'Conn
'
Me.Conn.ConnectionString = "workstation id=LXYZW;packet size=4096;user id=sa;integrated security=SSPI;data so" & _
"urce=""LXYZW\LXYZW"";persist security info=False;initial catalog=lxy_zhouwei"
'
'Objcmd
'
Me.Objcmd.Connection = Me.Conn End Sub
Protected WithEvents Conn As System.Data.SqlClient.SqlConnection
Protected WithEvents Objcmd As System.Data.SqlClient.SqlCommand
Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid '注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not IsPostBack Then
Conn.Open() Objcmd.CommandText = "select id ,stu_num,stu_num,stu_profession from users" Dim Obj_reader As SqlClient.SqlDataReader = Objcmd.ExecuteReader
DataGrid.DataSource = Obj_reader
DataGrid.DataBind() End If
End Sub Sub DataGrid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As DataGridPageChangedEventArgs) Handles DataGrid.PageIndexChanged
DataGrid.CurrentPageIndex = e.NewPageIndex
Conn.Open() Objcmd.CommandText = "select id,stu_num,stu_num,stu_profession from users" Dim Obj_reader As SqlClient.SqlDataReader = Objcmd.ExecuteReader
DataGrid.DataSource = Obj_reader
DataGrid.DataBind()
End Sub
End Class
那个分页显示出来拉,但是不能点击。是怎么回事啊?
本文介绍的这二种分页浏览记录类型虽然采用的数据库都是本地数据库,但对其他类型的数据库也是一样适用的,这只需要修改一下数据连接字符串就可以实现了,譬如如果采用了SQL Server数据库。此SQL Server数据库服务器是"Server1",数据库是"Data",用户名为缺省的"sa",没有设定密码。只需要把上面二段程序中的字符串"strConn"变换成: strConn = "Provider = SQLOLEDB.1 ; Persist Security Info = False ; User ID = sa ; Initial Catalog = Data ; Data Source = server1 "
建议将数据绑定写一个过程,在changed过程中调用
'在此处放置初始化页的用户代码
If Not IsPostBack Then
Conn.Open() Objcmd.CommandText = "select id ,stu_num,stu_num,stu_profession from users" Dim Obj_reader As SqlClient.SqlDataReader = Objcmd.ExecuteReader
DataGrid.DataSource = Obj_reader
DataGrid.DataBind() End If
End Sub Sub DataGrid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As DataGridPageChangedEventArgs) Handles DataGrid.PageIndexChanged
DataGrid.CurrentPageIndex = e.NewPageIndex
Conn.Open() Objcmd.CommandText = "select id,stu_num,stu_num,stu_profession from users" Dim Obj_reader As SqlClient.SqlDataReader = Objcmd.ExecuteReader
DataGrid.DataSource = Obj_reader
DataGrid.DataBind()
End Sub