分页功能 int curpage = Convert.ToInt32(this.Label2.Text.ToString().Trim()); PagedDataSource ps = new PagedDataSource(); sqlcon = new SqlConnection(strcon); SqlDataAdapter sda = new SqlDataAdapter("select * from tb_GoodsType", sqlcon); DataSet ds = new DataSet(); sda.Fill(ds, "tb_GoodsType"); ps.DataSource = ds.Tables["tb_GoodsType"].DefaultView; ps.AllowPaging = true; ps.PageSize = 2;//实现分页 //分页控件的控制 LinkButton1.Enabled = true; LinkButton2.Enabled = true; LinkButton3.Enabled = true; LinkButton4.Enabled = true; ps.CurrentPageIndex = curpage-1; if (curpage == 1) { this.LinkButton1.Enabled = false; this.LinkButton2.Enabled = false; } if (curpage == ps.PageCount) { this.LinkButton3.Enabled = false; this.LinkButton4.Enabled = false; } this.Label3.Text = Convert.ToString(ps.PageCount); DataList1.DataSource = ps; this.DataList1.DataKeyField = "GoodsTypeID"; DataList1.DataBind(); } |
|