问题如下:每次运行只能显示两页,好像和i的初值有关!希望大家看看,找找是那里的错!数据库文件已经上传
HTML源码:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="表格.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:label id="Label1" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 8px" runat="server"
Width="584px" Height="498px"></asp:label><asp:button id="Button1" style="Z-INDEX: 103; LEFT: 640px; POSITION: absolute; TOP: 32px" runat="server"
Text="上一页"></asp:button><asp:button id="Button2" style="Z-INDEX: 104; LEFT: 712px; POSITION: absolute; TOP: 32px" runat="server"
Text="下一页"></asp:button><asp:label id="Label2" style="Z-INDEX: 105; LEFT: 624px; POSITION: absolute; TOP: 96px" runat="server"
Width="160px"></asp:label></FONT></form>
</body>
</HTML>
cs源码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace 表格
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected DataSet mySet;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected int i=1;
protected System.Web.UI.WebControls.Label Label2;
protected string table="";
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
new_data();
this.Label2.Text="";
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public void print(string table)
{
string ss;
ss="<table border=\"1\" cellspacing=\"0\" bordercolor=\"#CCCC33\">";
if(table=="")
{
this.Label1.Text=ss+"<tr><td>table是空的</td></tr>";
}
else
{
this.Label1.Text=ss+table+"</table>";
}
}
public void get_data()
{
string sel="select * from passport";
OleDbConnection myCon=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("..\\user.mdb"));
OleDbCommand myCom=new OleDbCommand(sel,myCon);
OleDbDataReader myRead;
myCom.Connection.Open();
myRead=myCom.ExecuteReader();
while(myRead.Read())
{
string ss;
ss=i.ToString().Trim();
if(ss==myRead["ID"].ToString().Trim())
{
table=table+"<tr><td height=\"18\"><a href=localhost/"+myRead["ID"]+".html>"+myRead["申请人姓名"].ToString()+"</a></td><td height=\"18\">"+myRead["血型"].ToString()+"</td></tr>";
this.Label2.Text=this.Label2.Text+"[i="+i+"]"+"[id="+(int)myRead["ID"]+"]<br>";
break;
}
}
myRead.Close();
myCom.Connection.Close();
myCon.Close();
}
private void new_data()
{
table="";
int j;
for(j=0;j<5;j++)
{
get_data();
i=i+1;
}
print(table);
}
private void Button2_Click(object sender, System.EventArgs e)
{
new_data();
}
}
}
[此贴子已经被作者于2006-10-4 23:14:17编辑过]