下现是其中一种做法,VS.NET的代码
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="VBNET.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:TextBox id="TextBox1" style="Z-INDEX: 101;
LEFT: 32px;
POSITION: absolute;
TOP: 64px" runat="server"
Width="168px" Height="40px" Rows="2" Text='<%# DataBinder.Eval(DataSet11, "Tables[Products].DefaultView.[0].ProductName") %>'>
</asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 102;
LEFT: 232px;
POSITION: absolute;
TOP: 64px" runat="server"
Width="104px" Height="40px" Text="上一个"></asp:Button>
<asp:Button id="Button2" style="Z-INDEX: 103;
LEFT: 232px;
POSITION: absolute;
TOP: 120px" runat="server"
Width="104px" Height="40px" Text="下一个"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 104;
LEFT: 40px;
POSITION: absolute;
TOP: 24px" runat="server"
Width="184px" Height="32px">Label</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 105;
LEFT: 280px;
POSITION: absolute;
TOP: 24px" runat="server"
Width="200px" Height="32px">Label</asp:Label></FONT>
</form>
</body>
</HTML>
//*************************************************************************//
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.DataSet11 = New VBNET.DataSet1
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).begin
Init()
'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Products", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ProductID", "ProductID"), New System.Data.Common.DataColumnMapping("ProductName", "ProductName"), New System.Data.Common.DataColumnMapping("SupplierID", "SupplierID"), New System.Data.Common.DataColumnMapping("CategoryID", "CategoryID"), New System.Data.Common.DataColumnMapping("QuantityPerUnit", "QuantityPerUnit"), New System.Data.Common.DataColumnMapping("UnitPrice", "UnitPrice"), New System.Data.Common.DataColumnMapping("UnitsInStock", "UnitsInStock"), New System.Data.Common.DataColumnMapping("UnitsOnOrder", "UnitsOnOrder"), New System.Data.Common.DataColumnMapping("ReorderLevel", "ReorderLevel"), New System.Data.Common.DataColumnMapping("Discontinued", "Discontinued")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice" &
_
", UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM Products"
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "workstation id=MY;packet size=4096;integrated security=SSPI;data source=""MY/NetSD" &
_
"K"";persist security info=False;initial catalog=Northwind"
'
'DataSet11
'
Me.DataSet11.DataSetName = "DataSet1"
Me.DataSet11.Locale = New System.Globalization.CultureInfo("zh-CN")
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Protected WithEvents DataSet11 As VBNET.DataSet1
Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
'注意: 以下占位符声明是 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 Me.IsPostBack then
Me.DataBind()
Label1.Text = "一共 " &
DataSet11.Products.Count &
"条记录"
End If
End Sub
Private Sub Page_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.DataBinding
SqlDataAdapter1.Fill(DataSet11)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim inc As Integer = Me.ViewState.Item("inc")
If inc > 1 then
inc = inc - 1
End If
Me.ViewState.Item("inc") = inc
Me.SqlSelectCommand1.CommandText = Me.SqlSelectCommand1.CommandText &
_
" where ProductID = " &
inc
Label2.Text = "当前记录的ID是 " &
inc
DataBind()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim inc As Integer = Me.ViewState.Item("inc")
inc = inc + 1
Me.ViewState.Item("inc") = inc
Me.SqlSelectCommand1.CommandText = Me.SqlSelectCommand1.CommandText &
_
" where ProductID = " &
inc
Label2.Text = "当前记录的ID是 " &
inc
DataBind()
End Sub
End Class