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

📄 showguestbook.aspx.cs

📁 这是一个ASP.NET和数据库的程序
💻 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;
using System.Configuration;
namespace baogelyb
{
	/// <summary>
	/// showguestbook 的摘要说明。
	/// </summary>
	public class showguestbook : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataList DataList1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.Button Button4;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.Button Button5;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!this.IsPostBack)
			{
				this.Label2.Text="1";
				this.databind();
				this.TextBox1.Text="1";
			}
		}



//		public string ShowReply(bool IsReplyed, string replytime, string replycontent)
//		{
//			if (!IsReplyed)
//			{
//				return "";
//			}
//			else
//			{
//				return "<br><hr size=1 width=100% align=center><font color=#009966>管理员于 '"+replytime+"' 回复</font><br><font color=#666666>'"+replycontent.Replace("\r\n","<br>")+"</font>";
//			}
//		}
		private void databind()
		{
			//			int CID=Convert.ToInt32(Request.QueryString["id"]);
			int curPage=Convert.ToInt32(this.Label2.Text);
//			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["lyb"];
//			//定义连接字符串
//			string ConnStr="Provider=Microsoft.Jet.Sql.4.0;Data Source="+Server.MapPath(dbPath);
			//创建数据库对像
//			SqlConnection connection=new SqlConnection(ConnStr);
			SqlConnection connection=db.createconnection();

//			String mysql="SELECT * FROM lyb order by id desc";
			//			String mysql="SELECT * FROM Article where ispic=true order by ArticleID desc";
			SqlDataAdapter sda=new SqlDataAdapter();
			
            sda.SelectCommand=new SqlCommand("select * from lyb order by id desc",connection);
			DataSet ds=new DataSet();
			sda.Fill(ds,"lyb");
			System.Web.UI.WebControls.PagedDataSource ps=new PagedDataSource();
			ps.DataSource=ds.Tables["lyb"].DefaultView;
			ps.AllowPaging=true;
			ps.PageSize=5;
			ps.CurrentPageIndex=curPage-1;
			this.Button1.Enabled=true;
			this.Button2.Enabled=true;
			
			if(curPage==1)
			{
				this.Button1.Enabled=false;
			}
			if(curPage==ps.PageCount)
			{
				this.Button2.Enabled=false;
			}
			
			
			this.DataList1.DataSource=ps;
			this.DataList1.DataBind();
			this.Label3.Text=Convert.ToString(ps.PageCount);
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Button4.Click += new System.EventHandler(this.Button4_Click);
			this.Button5.Click += new System.EventHandler(this.Button5_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			this.Label2.Text=Convert.ToString(Convert.ToInt32(this.Label2.Text)-1);
			this.databind();
		}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			this.Label2.Text=Convert.ToString(Convert.ToInt32(this.Label2.Text)+1);
			this.databind();
		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			this.Label2.Text="1";
			this.databind();
		}

		private void Button4_Click(object sender, System.EventArgs e)
		{
			this.Label2.Text=Convert.ToString(Convert.ToInt32(this.Label3.Text));
			this.databind();
		}

		private void Button5_Click(object sender, System.EventArgs e)
		{
			if(this.TextBox1.Text.ToString()=="0")
			{
				this.Label2.Text="1";
				this.databind();
			}
			else if(this.TextBox1.Text.ToString()=="")
			{
				this.Label2.Text="1";
				this.databind();
			}
		  
			else
			{
				this.Label2.Text=Convert.ToString(this.TextBox1.Text);
				this.databind();
			}
		}
	}
}

⌨️ 快捷键说明

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