DataList分页方法一
SqlConnection conn = new SqlConnection();
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Product_gongqiu");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["Product_gongqiu"].DefaultView;
//开启分页
pds.AllowPaging = true;
//显示显示的行数
pds.PageSize = 8;
//定义变量保存当前页索引
int curPage;
//判断当前页是否有跳转请求
if (Request.QueryString["page"] != null)
curPage = Convert.ToInt32(Request.QueryString["page"]);
else
curPage = 1;
pds.CurrentPageIndex = curPage - 1;
Label1.Text = "当前第" + curPage.ToString() + "页";
Label2.Text = "共" + pds.PageCount.ToString() + "页";
if (!pds.IsFirstPage)
{ //定义"上一页"超级连接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引植
prev.NavigateUrl = "@@@.aspx?page=" + (curPage - 1) + "&sqltext=" + sql + "&tiaojiantext=" + tiaojian;
}
if (!pds.IsLastPage)
{ //下一页
next.NavigateUrl = "@@@.aspx?page=" + (curPage + 1) + "&sqltext=" + sql + "&tiaojiantext=" + tiaojian;
}
DataList1.DataSource = pds;
DataList1.DataBind();