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

📄 replypage.aspx.cs

📁 留言板得源代码 是初学网络的较好代码
💻 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 Aspnet
{
	/// <summary>
	/// Replypage 的摘要说明。
	/// </summary>
	public class Replypage : System.Web.UI.Page
	{
		protected SqlConnection myconnection=new SqlConnection();
		protected System.Web.UI.WebControls.HyperLink HyperLink1;
		protected System.Web.UI.WebControls.DataList DL_reply;
		protected System.Web.UI.WebControls.Label LB_subject;
		protected System.Web.UI.WebControls.Label LB_name;
		protected System.Web.UI.WebControls.Label LB_replies;
		protected System.Web.UI.WebControls.Label LB_time;
		protected System.Web.UI.WebControls.Label LB_content;
		protected System.Web.UI.WebControls.TextBox TB_reply;
		protected System.Web.UI.WebControls.Button BT_submit;
		protected System.Web.UI.WebControls.Button BT_reset;
		private static string id;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(Session.Count==0)//访问者没有登录			
				Response.Redirect("Index.aspx");
			else
			{
				if(!IsPostBack)
				{
					id=Request.Params["PostID"];
				}
				myconnection.ConnectionString="server=localhost;database=Aspnet;uid=sj;pwd=;";
				BindData();
			}
		}

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

		}
		#endregion
		
		private void BindData()
		{
			//留言者的留言情况
			string selectstr="select * from Newpost where PostID="+id;
			SqlDataAdapter da1=new SqlDataAdapter(selectstr,myconnection);
			//留言者所有留言回复情况
			string selstr="select * from Newpost where ParentID="+id;
			SqlDataAdapter da2=new SqlDataAdapter(selstr,myconnection);
			DataSet ds=new DataSet();
			da1.Fill(ds,"host");
			da2.Fill(ds,"guest");
			//留言主题
			LB_subject.Text=ds.Tables["host"].Rows[0][3].ToString();
			//留言回复次数
			int recount=ds.Tables["guest"].Rows.Count;
			LB_replies.Text=recount.ToString ();
			//留言发表时间
			LB_time.Text=ds.Tables["host"].Rows[0][4].ToString();
			//留言内容
			LB_content.Text=ds.Tables["host"].Rows[0][5].ToString();
			//留言的作者
			LB_name.Text=ds.Tables["host"].Rows[0][2].ToString();
			//绑定数据
			DL_reply.DataSource=ds;
			DL_reply.DataMember="guest";
			DL_reply.DataBind();
			this.DataBind();
			myconnection.Close();
		}

		private void BT_submit_Click(object sender, System.EventArgs e)
		{
			string UserName=Session["username"].ToString();
			string insstr="insert into Newpost (ParentID,UserName,Subject,RegTime,Message) values ("+id+",'"+UserName+"','re',getdate(),'"+TB_reply.Text.ToString()+"')";			
			SqlCommand inscom=new SqlCommand(insstr,myconnection);
			inscom.Connection.Open();
			inscom.ExecuteNonQuery();
			inscom.Connection.Close();
			myconnection.Close();
			BindData();
			TB_reply.Text="";
		}

		private void BT_reset_Click(object sender, System.EventArgs e)
		{
			TB_reply.Text="";
		}




	}
}

⌨️ 快捷键说明

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