⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 handleevent.cs

📁 ASP.net动画教程
💻 CS
字号:
using System;
using System.Data;
using System.Collections;
using System.Data.OleDb;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class HandleEvent : Page
{
	//首先申明主程序中使用的变量
	public Label lblRecordCount,lblCurrentPage,lblPageCount;
	public DataList score;
	public LinkButton lbnPrevPage,lbnNextPage;

	OleDbConnection MyConn;
	int PageSize,RecordCount,PageCount,CurrentPage;
	public void Page_Load(Object src,EventArgs e)
	{
		//设定PageSize
		PageSize = 5;
		
		//连接语句
		string MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\asp.net\\db\\db1.mdb";
		MyConn = new OleDbConnection(MyConnString);
		MyConn.Open();

		//第一次请求执行
		if(!Page.IsPostBack)
		{
			ListBind();
			CurrentPage = 0;
			ViewState["PageIndex"] = 0;

			//计算总共有多少记录
			RecordCount = CalculateRecord();
			lblRecordCount.Text = RecordCount.ToString();

			//计算总共有多少页
			PageCount = RecordCount/PageSize;
			lblPageCount.Text = PageCount.ToString();
			ViewState["PageCount"] = PageCount;
		}
	}
	//计算总共有多少条记录
	public int CalculateRecord()
	{
		int intCount;
		string strCount = "select count(*) as co from Score";
		OleDbCommand MyComm = new OleDbCommand(strCount,MyConn);
		OleDbDataReader dr = MyComm.ExecuteReader();
		if(dr.Read())
		{
			intCount = Int32.Parse(dr["co"].ToString());
		}
		else
		{
			intCount = 0;
		}
		dr.Close();
		return intCount;
	}

	ICollection CreateSource()
	{
		
		int StartIndex;
		
		//设定导入的起终地址
		StartIndex	= CurrentPage*PageSize;
		string strSel = "select * from Score";
		DataSet ds = new DataSet();

		OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSel,MyConn);
		MyAdapter.Fill(ds,StartIndex,PageSize,"Score");
		
		return ds.Tables["Score"].DefaultView;
	}
	public void ListBind()
	{
		score.DataSource = CreateSource();
		score.DataBind();
		
		lbnNextPage.Enabled = true;
		lbnPrevPage.Enabled = true;
		if(CurrentPage==(PageCount-1)) lbnNextPage.Enabled = false;
		if(CurrentPage==0) lbnPrevPage.Enabled = false;
		lblCurrentPage.Text = (CurrentPage+1).ToString();

	}

	public void Page_OnClick(Object sender,CommandEventArgs e)
	{
		CurrentPage = (int)ViewState["PageIndex"];
		PageCount	= (int)ViewState["PageCount"];

		string cmd = e.CommandName;
		//判断cmd,以判定翻页方向
		switch(cmd)
		{
			case "next":
				if(CurrentPage<(PageCount-1)) CurrentPage++;
				break;
			case "prev":
				if(CurrentPage>0) CurrentPage--;
				break;
		}

		ViewState["PageIndex"] = CurrentPage;

		ListBind();
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -