forum2.aspx.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:4k
源码类别:
C#编程
开发平台:
Others
- 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 mbord5
- {
- /// <summary>
- /// WebForm1 的摘要说明。
- /// </summary>
- public class forum2 : System.Web.UI.Page
- {
- protected System.Web.UI.WebControls.Label Label1;
- protected System.Web.UI.WebControls.Label errmess;
- protected System.Web.UI.WebControls.DataGrid DataGrid1;
- protected System.Web.UI.WebControls.TextBox message;
- protected System.Web.UI.WebControls.TextBox subject;
- protected System.Web.UI.WebControls.TextBox email;
- protected System.Web.UI.WebControls.TextBox name;
- protected System.Web.UI.WebControls.Label Label2;
- protected System.Web.UI.WebControls.Button Button1;
- public int startIndex;
- private void Page_Load(object sender, System.EventArgs e)
- {
- //当刚载入页面时候执行下面的程序。
- if(!IsPostBack)
- {
- startIndex =0;
- }
- //绑定DataGrid
- Binding();
- // 在此处放置用户代码以初始化页面
- }
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
- this.Button1.Click += new System.EventHandler(this.Button1_Click);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- //链接数据库,绑定DataGrid
- public void Binding()
- {
- String Provider, ConnStr;
- Provider = "Microsoft.Jet.OLEDB.4.0;";
- ConnStr = "Provider="+Provider+"Data Source="+Server.MapPath("board.mdb");
- //进行链接数据库
- //从newpost 表中选择记录
- string strCom = "SELECT postid ,subject ,name ,replies ,views ,date ,message FROM newpost ORDER BY postid DESC";
- //打开链接
- DataSet myDataSet = new DataSet();
- OleDbDataAdapter myCommand =new OleDbDataAdapter(strCom,ConnStr);
- //填充DataSet
- myCommand.Fill(myDataSet,"newpost") ;
- //关闭链接
- //myConn.Close();
- //设置表newpost的DataView
- DataGrid1.DataSource = myDataSet.Tables["newpost"].DefaultView ;
- //绑定 DataGrid
- DataGrid1.DataBind();
- }
- private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
- {
- //算好当前页的代码显示 并绑定
- startIndex = e.NewPageIndex*DataGrid1.PageSize;
- DataGrid1.CurrentPageIndex = e.NewPageIndex;
- Binding();
- }
- private void Button1_Click(object sender, System.EventArgs e)
- {
- //先进行判断
- if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!="")
- {
- //得到当前日期时间
- DateTime now = DateTime.Now ;
- errmess.Text="" ;
- //下面我们用一个字符串向postmessage.aspx传送数据
- String req = "name="+System.Web.HttpUtility.UrlEncode(name.Text, System.Text.Encoding.UTF8);
- req+="&&email="+System.Web.HttpUtility.UrlEncode(email.Text, System.Text.Encoding.UTF8);
- req+="&&subject="+System.Web.HttpUtility.UrlEncode(subject.Text, System.Text.Encoding.UTF8);
- //得到发表者的IP地址
- req+="&&ip="+System.Web.HttpUtility.UrlEncode( Request.UserHostAddress.ToString(), System.Text.Encoding.UTF8);
- req+="&&date="+System.Web.HttpUtility.UrlEncode(now.ToString(), System.Text.Encoding.UTF8);
- req+="&&newpost="+System.Web.HttpUtility.UrlEncode("yes", System.Text.Encoding.UTF8);
- req+="&&message="+System.Web.HttpUtility.UrlEncode(message.Text, System.Text.Encoding.UTF8);
- //'yes' 用来标示这是一个新主题
- //向postmessage.aspx传值.
- Response.Redirect(("postmessage2.aspx?" + req));
- }
- else
- {
- errmess.Text="对不起,您还有些信息没填!<br>" ;
- }
- }
- /*
- void ChangePage(Object sender, DataGridPageChangedEventArgs e)
- {
- startIndex = e.NewPageIndex*DataGrid1.PageSize;
- DataGrid1.CurrentPageIndex = e.NewPageIndex;
- Binding();
- }
- */
- }
- }