求一个类似于百度的DataList分页,谢谢!!
- 提问者网友:绫月
- 2021-05-03 21:42
- 五星知识达人网友:一把行者刀
- 2021-05-03 22:58
public void BindData()
24 {
25 SqlConnection conn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
26
27 SqlDataAdapter da = new SqlDataAdapter("select UserID,C_Name,E_Name,QQ,star_signs from Demo_User", conn);
28
29 DataSet ds = new DataSet();
30 da.Fill(ds, "Table");
31
32 DataTable dt = ds.Tables["Table"];
33
34 PagedDataSource objPage = new PagedDataSource();
35 objPage.DataSource = ds.Tables["Table"].DefaultView;
36 objPage.AllowPaging = true;
37 objPage.PageSize = 12;
38 int CurPage;
39 if (Request.QueryString["Page"] != null)
40 {
41 CurPage = Convert.ToInt32(Request.QueryString["Page"]);
42 }
43 else
44 {
45 CurPage = 1;
46 }
47 objPage.CurrentPageIndex = CurPage - 1;
48
49 this.lblCountpage.Text = " " + objPage.PageCount + " ";
50 lblCurPage.Text = " " + CurPage.ToString() + " ";
51 lblCountRec.Text = " " + dt.Rows.Count.ToString() + " ";
52 //如果当前页面不是首页
53 if (!objPage.IsFirstPage)
54 //定义"上一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值
55 lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
56 //如果当前页面不是最后一页
57 if (!objPage.IsLastPage)
58 //定义"下一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值
59 lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
60
61 //进行数据绑定
62 DataList.DataSource = objPage;
63 DataList.DataBind();
64 }
65 }
自己修改一下就可以了
具体参考 http://www.aspx58.com.cn/Default_AC_View.aspx?ID=140