我觉得datalist样式很好确定,也很好用。
分页代码和Reapter差不多,给你看看,不知道是否对你有用哦!
public void search1()
{
int curpage = int.Parse(this.Labji.Text); //第几页
SqlConnection con = new SqlConnection("server=.;database=aa;uid=sa;pwd=''");
con.Open();
SqlDataAdapter da = new SqlDataAdapter(str, con);
DataSet ds = new DataSet();
da.Fill(ds);
System.Web.UI.WebControls.PagedDataSource dp = new PagedDataSource();//设置分页
dp.DataSource = ds.Tables[0].DefaultView;
dp.AllowPaging = true;
dp.PageSize = 5;
dp.CurrentPageIndex = curpage - 1;
this.LkButshou.Enabled = true; //首页按钮
this.LButshang.Enabled = true; //上一页按钮
this.LButxia.Enabled = true; //下一页按钮
this.LButwei.Enabled = true; //尾页按钮
if (curpage == 1)
{
this.LkButshou.Enabled = false;
this.LButshang.Enabled = false;
this.LButxia.Enabled = true;
this.LButwei.Enabled = true;
}
if (curpage == dp.PageCount)
{
this.LkButshou.Enabled = true;
this.LButshang.Enabled = true;
this.LButxia.Enabled = false;
this.LButwei.Enabled = false;
}
this.DataList1.DataSource = dp;
this.DataList1.DataBind();
SqlCommand cmd = new SqlCommand("select count(*) from ProductInfo", con);
DB.pagecount = Convert.ToString(cmd.ExecuteScalar());
DB.pagecount = Convert.ToString(dp.PageCount);
this.Labgji.Text = DB.pagecount; //共几页 调用DB类中的 public static String pagecount;
}
protected void LButshang_Click(object sender, EventArgs e)
{
this.Labji.Text = Convert.ToString(int.Parse(this.Labji.Text) - 1);
this.search1();
}
protected void LButxia_Click(object sender, EventArgs e)
{
this.Labji.Text = Convert.ToString(int.Parse(this.Labji.Text) +1);
this.search1();
}
protected void LkButshou_Click(object sender, EventArgs e)
{
this.Labji.Text = "1";
this.search1();
}
protected void LButwei_Click(object sender, EventArgs e)
{
this.Labji.Text = DB.pagecount;
this.search1();
}