DataSet ds; SqlDataAdapter dr; SqlCommand com; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection con = new SqlConnection("server=.;uid=sa;database=数据库"); con.Open(); com = new SqlCommand(); com.Connection = con; com.CommandText = "select count(*) from Employees"; AspNetPager1.AlwaysShow=true; AspNetPager1.PageSize=15; AspNetPager1.RecordCount = (int)com.ExecuteScalar(); con.Close(); DataListDataBind(); } } private void DataListDataBind() { SqlConnection con = new SqlConnection("server=.;uid=sa;database=数据库"); dr = new SqlDataAdapter("select * from Employees", con); ds = new DataSet(); dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "Employees"); DataList1.DataSource = ds.Tables["Employees"]; DataList1.DataBind(); } protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { AspNetPager1.CurrentPageIndex = e.NewPageIndex; DataListDataBind(); }