求助.NET分页显示代码?
5个回答
展开全部
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PracticeMyBookShopBLL;
using PracticeMyBookShopModels;
public partial class HotBookList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//首次加载,赋初值
ViewState["Page"] = 0;
}
Databind();
}
private void Databind()
{
PagedDataSource pdsList = new PagedDataSource();
//对PagedDataSource 对象的相关属性赋值
pdsList.DataSource = BookManager.GetHotBooks();
pdsList.AllowPaging = true;
pdsList.PageSize = 5;
pdsList.CurrentPageIndex = Pager;
lblCurrentPage.Text = "第 " + (pdsList.CurrentPageIndex + 1).ToString() + " 页 共 " + pdsList.PageCount.ToString() + " 页";
SetEnable(pdsList);
//把PagedDataSource 对象赋给DataList控件
dlBooks.DataSource = pdsList;
dlBooks.DataBind();
}
private void SetEnable(PagedDataSource pds)
{
lnkbtnPre.Enabled = true;
lnkbtnNext.Enabled = true;
if (pds.IsFirstPage)
lnkbtnPre.Enabled = false;
if (pds.IsLastPage)
lnkbtnNext.Enabled = false;
}
/// <summary>
/// 当前页数
/// </summary>
private int Pager
{
get
{
return (int)ViewState["Page"];
}
set
{
ViewState["Page"] = value;
}
}
protected void lnkbtnPre_Click(object sender, EventArgs e)
{
Pager--;
Databind();
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
Pager++;
Databind();
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PracticeMyBookShopBLL;
using PracticeMyBookShopModels;
public partial class HotBookList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//首次加载,赋初值
ViewState["Page"] = 0;
}
Databind();
}
private void Databind()
{
PagedDataSource pdsList = new PagedDataSource();
//对PagedDataSource 对象的相关属性赋值
pdsList.DataSource = BookManager.GetHotBooks();
pdsList.AllowPaging = true;
pdsList.PageSize = 5;
pdsList.CurrentPageIndex = Pager;
lblCurrentPage.Text = "第 " + (pdsList.CurrentPageIndex + 1).ToString() + " 页 共 " + pdsList.PageCount.ToString() + " 页";
SetEnable(pdsList);
//把PagedDataSource 对象赋给DataList控件
dlBooks.DataSource = pdsList;
dlBooks.DataBind();
}
private void SetEnable(PagedDataSource pds)
{
lnkbtnPre.Enabled = true;
lnkbtnNext.Enabled = true;
if (pds.IsFirstPage)
lnkbtnPre.Enabled = false;
if (pds.IsLastPage)
lnkbtnNext.Enabled = false;
}
/// <summary>
/// 当前页数
/// </summary>
private int Pager
{
get
{
return (int)ViewState["Page"];
}
set
{
ViewState["Page"] = value;
}
}
protected void lnkbtnPre_Click(object sender, EventArgs e)
{
Pager--;
Databind();
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
Pager++;
Databind();
}
}
展开全部
Gridview自带分页,但是不好用,你可以用一个分页控件,但是只是一个样式,里面的方法还得自己写,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以自己写存储过程。在数据库上分页是比较好的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Gridview可以分页显示数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询