日期:2014-05-20 浏览次数:20797 次
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Bind(this.Pager.CurrentPageIndex,this.Pager.PageSize);
}
}
public void Bind(int PageIndex,int PageSize)
{
using(NorthWindDataContext nor = new NorthWindDataContext())
{
var suppliers = from s in nor.Suppliers
where s.Products.Count > 4
select s;
this.Repeater1.DataSource = suppliers;
this.Repeater1.DataBind();
var result = from c in nor.Customers
join o in nor.Orders
on c.CustomerID equals o.CustomerID
into custorder
from o in custorder
select new
{
Customer = c.CompanyName,
OrderDate = o.OrderDate,
OrderTotal = o.Order_Details.Sum(p => p.UnitPrice)
};
this.GridView1.DataSource=result.Skip((PageIndex-1)*PageSize).Take(PageSize);
this.GridView1.DataBind();
this.Pager.RecordCount = result.Count();
this.Pager.PageSize = GridView1.PageSize;
}
}
protected void Pager_PageChanged(object sender, EventArgs e)
{
this.GridView1.PageIndex = this.Pager.CurrentPageIndex;
Bind(this.GridView1.PageIndex, this.Pager.PageSize);
}
}