using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Manage_TestNews : System.Web.UI.Page ... { NewsList nl = new NewsList();//数据接口 protected void Page_Load(object sender, EventArgs e) ...{ if (!IsPostBack) ...{ this.Label6.Text = "1";//第一次为第一页 this.databind(); } } private void databind() ...{ int currPage = Convert.ToInt32(this.Label6.Text.Trim()) - 1; System.Web.UI.WebControls.PagedDataSource pd = new PagedDataSource(); pd.DataSource = nl.RetDs().Tables[0].DefaultView; pd.AllowPaging = true; pd.PageSize = 2; pd.CurrentPageIndex = currPage; this.LinkButton2.Enabled = true; this.LinkButton3.Enabled = true; this.DataList1.DataSource = pd; this.DataList1.DataBind(); Label3.Text =Convert.ToString((pd.PageCount)); Label6.Text =Convert.ToString(pd.CurrentPageIndex+1); if (currPage == 0) this.LinkButton2.Enabled = false; if (currPage == pd.PageCount - 1) this.LinkButton3.Enabled = false; }//首页 protected void LinkButton1_Click(object sender, EventArgs e) ...{ this.Label6.Text = "1"; this.databind(); }//上一页 protected void LinkButton2_Click(object sender, EventArgs e) ...{ this.Label6.Text = Convert.ToString(Convert.ToInt32(Label6.Text) - 1); this.databind(); }//下一页 protected void LinkButton3_Click(object sender, EventArgs e) ...{ this.Label6.Text = Convert.ToString(Convert.ToInt32(Label6.Text) + 1); this.databind(); }//最后一页 protected void LinkButton4_Click(object sender, EventArgs e) ...{ this.Label6.Text = this.Label3.Text; this.databind(); }}