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

📄 browse.aspx.cs

📁 c#网络编程及应用-刘瑞新
💻 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.SqlClient;

namespace WebApplication
{
	/// <summary>
	/// browse 的摘要说明。
	/// </summary>
	public class browse : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.Button ButtonFirst;
		protected System.Web.UI.WebControls.Button ButtonPre;
		protected System.Web.UI.WebControls.Button ButtonLast;
		protected System.Web.UI.WebControls.Button ButtonCurrent;
		protected System.Web.UI.WebControls.Button ButtonNext;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			DataSet dataset=new DataSet();
			SqlConnection conn=new SqlConnection(MyClass.ConnString);
			SqlDataAdapter adapter=
				new SqlDataAdapter("SELECT * from loginuser order by logintime",conn);
			adapter.Fill(dataset,"loginuser");
			this.DataGrid1.DataSource=dataset;
			this.DataGrid1.DataMember=dataset.Tables["loginuser"].ToString();
			this.DataGrid1.DataBind();
			ShowPosition();

		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.ButtonFirst.Click += new System.EventHandler(this.ButtonFirst_Click);
			this.ButtonPre.Click += new System.EventHandler(this.ButtonPre_Click);
			this.ButtonNext.Click += new System.EventHandler(this.ButtonNext_Click);
			this.ButtonLast.Click += new System.EventHandler(this.ButtonLast_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void ButtonFirst_Click(object sender, System.EventArgs e)
		{
			this.DataGrid1.CurrentPageIndex = 0;
			this.DataGrid1.DataBind();
			ShowPosition();

		}

		private void ButtonPre_Click(object sender, System.EventArgs e)
		{
			if(this.DataGrid1.CurrentPageIndex>0)
			{
				this.DataGrid1.CurrentPageIndex -= 1;
				this.DataGrid1.DataBind();
				ShowPosition();
			}

		}

		private void ButtonNext_Click(object sender, System.EventArgs e)
		{
			if(this.DataGrid1.CurrentPageIndex<this.DataGrid1.PageCount-1)
			{
				this.DataGrid1.CurrentPageIndex += 1;
				this.DataGrid1.DataBind();
				ShowPosition();
			}

		}

		private void ButtonLast_Click(object sender, System.EventArgs e)
		{
			this.DataGrid1.CurrentPageIndex=this.DataGrid1.PageCount-1;
			this.DataGrid1.DataBind();
			ShowPosition();

		}
		private void ShowPosition()
		{
			this.ButtonCurrent.Text=string.Format("{0} of {1}",
				this.DataGrid1.CurrentPageIndex+1,this.DataGrid1.PageCount);
		}

	}
}

⌨️ 快捷键说明

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