谁能提供一段网页分页的代码?要求在没有分页的时候分页按钮不显示出来。
答案:1 悬赏:60 手机版
解决时间 2021-02-12 12:34
- 提问者网友:我们很暧昧
- 2021-02-12 08:18
只要“下一页”“上一页”两个按钮,其他内容一概不要。要程序能使用的
最佳答案
- 五星知识达人网友:杯酒困英雄
- 2021-02-12 09:34
页面代码:
<div style="text-align:left;margin:20px 0 20px 0;">
<asp:Label runat="server" ID="lblCurrentPage"></asp:Label>
<asp:Button ID="btnPrev" runat="server" Text="上一页" OnClick="btnPrev_Click" BackColor="#C0FFC0" BorderColor="SeaGreen" BorderStyle="Solid" BorderWidth="1px" CssClass="anniu" Font-Size="12px" ForeColor="Black" Font-Bold="False" Height="16px" Width="57px"/>
<asp:Button ID="btnNext" runat="server" Text="下一页" OnClick="btnNext_Click" BackColor="#C0FFC0" BorderColor="SeaGreen" BorderStyle="Solid" BorderWidth="1px" CssClass="anniu" Font-Size="12px" ForeColor="Black" Font-Bold="False" Height="16px" Width="57px"/>
后台分页代码:
//页面数据加载
private void BooksDataBind()
{
PagedDataSource pdsBooks = new PagedDataSource();
//对页面相关属性赋值
pdsBooks.DataSource = BookManager.GetBooksByCategoryId(Convert.ToInt32(ViewState["CategoryId"]),ViewState["OrderBy"].ToString());
pdsBooks.AllowPaging = true;
pdsBooks.PageSize = 4;
pdsBooks.CurrentPageIndex = (int)ViewState["Page"];
this.lblCurrentPage.Text = "第" + (pdsBooks.CurrentPageIndex + 1).ToString() + "页,共" + pdsBooks.PageCount.ToString() + "页";
//设置翻页按钮是否可用
btnPrev.Enabled = true;
btnNext.Enabled = true;
if (pdsBooks.IsFirstPage) btnPrev.Enabled = false;
if (pdsBooks.IsLastPage) btnNext.Enabled = false;
//绑定页面数据
this.dlBooks.DataSource = pdsBooks;
this.dlBooks.DataBind();
}
//下一页
protected void btnNext_Click(object sender, EventArgs e)
{
ViewState["Page"] = (int)ViewState["Page"]+1;
BooksDataBind();
}
//上一页
protected void btnPrev_Click(object sender, EventArgs e)
{
ViewState["Page"] = (int)ViewState["Page"] -1;
BooksDataBind();
}
protected void btnDate_Click(object sender, EventArgs e)
{
ViewState["OrderBy"] = "PublishDate";
ViewState["Page"] = 0;
btnDate.Enabled = false;
btnPrice.Enabled = true;
BooksDataBind();
}
protected void btnPrice_Click(object sender, EventArgs e)
{
ViewState["OrderBy"] = "UnitPrice";
ViewState["Page"] = 0;
btnPrice.Enabled = false;
btnDate.Enabled = true;
BooksDataBind();
}
<div style="text-align:left;margin:20px 0 20px 0;">
<asp:Label runat="server" ID="lblCurrentPage"></asp:Label>
<asp:Button ID="btnPrev" runat="server" Text="上一页" OnClick="btnPrev_Click" BackColor="#C0FFC0" BorderColor="SeaGreen" BorderStyle="Solid" BorderWidth="1px" CssClass="anniu" Font-Size="12px" ForeColor="Black" Font-Bold="False" Height="16px" Width="57px"/>
<asp:Button ID="btnNext" runat="server" Text="下一页" OnClick="btnNext_Click" BackColor="#C0FFC0" BorderColor="SeaGreen" BorderStyle="Solid" BorderWidth="1px" CssClass="anniu" Font-Size="12px" ForeColor="Black" Font-Bold="False" Height="16px" Width="57px"/>
后台分页代码:
//页面数据加载
private void BooksDataBind()
{
PagedDataSource pdsBooks = new PagedDataSource();
//对页面相关属性赋值
pdsBooks.DataSource = BookManager.GetBooksByCategoryId(Convert.ToInt32(ViewState["CategoryId"]),ViewState["OrderBy"].ToString());
pdsBooks.AllowPaging = true;
pdsBooks.PageSize = 4;
pdsBooks.CurrentPageIndex = (int)ViewState["Page"];
this.lblCurrentPage.Text = "第" + (pdsBooks.CurrentPageIndex + 1).ToString() + "页,共" + pdsBooks.PageCount.ToString() + "页";
//设置翻页按钮是否可用
btnPrev.Enabled = true;
btnNext.Enabled = true;
if (pdsBooks.IsFirstPage) btnPrev.Enabled = false;
if (pdsBooks.IsLastPage) btnNext.Enabled = false;
//绑定页面数据
this.dlBooks.DataSource = pdsBooks;
this.dlBooks.DataBind();
}
//下一页
protected void btnNext_Click(object sender, EventArgs e)
{
ViewState["Page"] = (int)ViewState["Page"]+1;
BooksDataBind();
}
//上一页
protected void btnPrev_Click(object sender, EventArgs e)
{
ViewState["Page"] = (int)ViewState["Page"] -1;
BooksDataBind();
}
protected void btnDate_Click(object sender, EventArgs e)
{
ViewState["OrderBy"] = "PublishDate";
ViewState["Page"] = 0;
btnDate.Enabled = false;
btnPrice.Enabled = true;
BooksDataBind();
}
protected void btnPrice_Click(object sender, EventArgs e)
{
ViewState["OrderBy"] = "UnitPrice";
ViewState["Page"] = 0;
btnPrice.Enabled = false;
btnDate.Enabled = true;
BooksDataBind();
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯