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 ContainerText.DB;
using System.Data.SqlClient;
namespace ContainerText.DataList
{
///
/// DetachPage 的摘要说明。
///
public partial class DetachPage : System.Web.UI.Page
{
DataSet ds;
SqlDataAdapter dr;
int num;
protected void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
Label2.Text = "1";
DataListDataBind();
}
}
private void DataListDataBind()
{
num = Convert.ToInt32(Label2.Text);
SqlConnection con = new SqlConnection
("server=.;uid=sa;database=数据库");
dr = new SqlDataAdapter("select * from
Employees",con);
ds = new DataSet();
dr.Fill(ds,"Employees");
PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["Employees"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 3;
ps.CurrentPageIndex = num - 1;
this.Button1.Enabled = true;
this.Button2.Enabled = true;
if(num==1)
{
this.Button1.Enabled = false;
}
if(num==ps.PageCount)
{
this.Button2.Enabled = false;
}
DataList1.DataSource = ps;
DataList1.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
}
#endregion
protected void Button2_Click(object sender, System.EventArgs
e)
{
Label2.Text = Convert.ToString(Convert.ToInt32
(Label2.Text) + 1);
DataListDataBind();
}
protected void Button1_Click(object sender, System.EventArgs
e)
{
Label2.Text = Convert.ToString(Convert.ToInt32
(Label2.Text) - 1);
DataListDataBind();
}
}
}
html