1个回答
展开全部
可以用数据库分页功能或者用自带的datalist分页。不过自带的datalist分页数据传输量很大不建议。
你可以去看看第3方的。net分页控件一般都是用数据库分页语句做的。
下面是datalist分页代码,不建议使用。你要的话我就重网上COPY下来了。
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();
}
}
你可以去看看第3方的。net分页控件一般都是用数据库分页语句做的。
下面是datalist分页代码,不建议使用。你要的话我就重网上COPY下来了。
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();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询