?? guestbook_list.aspx.cs
字號(hào):
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.Text;
using System.IO;
using System.Configuration;
namespace baogelyb
{
/// <summary>
/// guestbook_list 的摘要說明。
/// </summary>
public class guestbook_list : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid GonGaoGrid;
protected Wuqi.Webdiyer.AspNetPager haha;
private void Page_Load(object sender, System.EventArgs e)
{
if(Session["name"]==null||Session["name"].ToString()=="false")
{
Response.Redirect("fail.htm");
}
if(!this.IsPostBack)
{
SqlConnection objConnection=db.createconnection();
SqlCommand objCommand=new SqlCommand("select count(*) from lyb",objConnection);
objConnection.Open();
haha.RecordCount=(int)objCommand.ExecuteScalar();
objConnection.Close();
BindGrid();
}
}
protected void BindGrid()
{
//取得數(shù)據(jù)庫路徑
// string dbPath=System.Configuration.ConfigurationSettings.AppSettings["lyb"];
// //定義數(shù)據(jù)庫連接字符串
// string ACconnStr="Provider=Microsoft.Jet.Sql.4.0;Data Source="+Server.MapPath(dbPath);
//創(chuàng)建數(shù)據(jù)庫連接對(duì)像
SqlConnection ACconn=db.createconnection();
ACconn.Open();
//定義SQL語句
string ACsql="select * from lyb order by id desc";
//定義數(shù)據(jù)適配器
SqlDataAdapter ACda=new SqlDataAdapter(ACsql,ACconn);
//創(chuàng)建數(shù)據(jù)集
DataSet ACds=new DataSet();
//從指定的索引開始取PageSize條記錄
ACda.Fill(ACds,haha.PageSize*(haha.CurrentPageIndex-1),haha.PageSize,"CurDataTable");
//創(chuàng)建所有數(shù)集
ACda.Fill(ACds,"AllDataTable");
//設(shè)置DataGrid控件實(shí)際顯示的項(xiàng)數(shù)
GonGaoGrid.VirtualItemCount=ACds.Tables["AllDataTable"].Rows.Count;
//數(shù)據(jù)綁定
GonGaoGrid.DataSource=ACds.Tables["CurDataTable"];
GonGaoGrid.DataBind();
haha.CustomInfoText=" 共有留言<font color=\"blue\"><b>"+haha.RecordCount.ToString()+"</b></font>條";
haha.CustomInfoText+=" 共有<font color=\"blue\"><b>"+haha.PageCount.ToString()+"</b></font>頁";
haha.CustomInfoText+=" 當(dāng)前為第<font color=\"red\"><b>"+haha.CurrentPageIndex.ToString()+"</b></font>頁";
ACda.Dispose();
ACconn.Close();
}
#region Web 窗體設(shè)計(jì)器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.haha.PageChanged += new Wuqi.Webdiyer.PageChangedEventHandler(this.haha_PageChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void haha_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
haha.CurrentPageIndex=e.NewPageIndex;
this.BindGrid();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -