webdiyer aspnet pager最近又用这个。还是记录下。
这个是页面里的代码
需要在上面引入:
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<webdiyer:AspNetPager ID="AspNetPager1" PageSize="20" runat="server" OnPageChanged="AspNetPager1_PageChanged" AlwaysShow="True" CssClass="fypage" CurrentPageButtonClass=".fypage span"> </webdiyer:AspNetPager>
后台用法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JGDJWeb.Model;
using Wuqi.Webdiyer;
namespace JGDJWeb.Special
{
public partial class List : System.Web.UI.Page
{
private int pageSize = 20;//每页显示的数量
private string ClassNO = "";//当前页面的栏目编号
protected void Page_Load(object sender, EventArgs e)
{
this.AspNetPager1.PageSize = pageSize;//为分布控件设置pageSize
string classNo = Request.QueryString["ClassNo"] ?? "";//取得列表栏目
JY_News_Classs news_Classs = new JY_News_Classs() { ClassCName = "", ClassNo = "" };
using (JGDJEntities entities = new JGDJEntities())
{
news_Classs = entities.JY_News_Classs.FirstOrDefault(t => t.ClassNo == classNo) ?? new JY_News_Classs() { ClassCName = "", ClassNo = "" };
}
this.LabelTitle.Text = news_Classs.ClassCName;
this.HyperLinkNav.Text = news_Classs.ClassCName;
ClassNO = news_Classs.ClassNo;
if (!IsPostBack)
{
RepeaterDataBind(AspNetPager1, news_Classs.ClassNo);
}
}
private void RepeaterDataBind(AspNetPager pager, string classNo)
{
using (JGDJEntities entities = new JGDJEntities())
{
//要求审核通过
var news = entities.JY_Newss.Where(c => c.CheckStatus == 1 && c.JY_NewsClass.Any(no => no.ClassNo == classNo));//定义一个上下文,方便直接引用
pager.RecordCount = news.Count();//为分布控件的总记录数赋值,这样分布控件可以自动算出有多少页
var data = news.OrderByDescending(t => t.CreateTime).Skip((pager.CurrentPageIndex - 1) * pager.PageSize).Take(pager.PageSize).ToList();//根据分页控件的CurrentPageIndex和PageSize取出相应的记录
Repeater1.DataSource = data;
Repeater1.DataBind();
}
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
RepeaterDataBind(sender as AspNetPager, ClassNO);
}
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。