日期:2014-05-18  浏览次数:20452 次

asp.net2.0 大家如何做Repeater分页的
我是在表头放置了 排序按钮 做的 

感觉比较麻烦 

有代码的贴出来

------解决方案--------------------
自己写个类从Repeat继承,然后实现分页功能即可,下面的代码是偷懒了写的,没有使用事件委托,喜欢的话可参考
===========================================
using System;
using System.Text;
using System.Collections;
using System.Web.UI.WebControls;

namespace MyWebControlLibrary
{
/// <summary>
/// 一个简单自定义控件,只在原始的Repeater控件上添加了分页功能
/// </summary>
public class CustomGrid : Repeater
{
private string emptyText;
private IList dataSource;
private int pageSize = 10;
private int itemCount;
private int currentPageIndex;
/// <summary>
/// 当前页码
/// </summary>
public int CurrentPageIndex
{
get { return currentPageIndex; }
set
{
if (value > PageCount)
{
currentPageIndex = PageCount;
}
else if (value < 1)
{
currentPageIndex = 1;
}
else
{
currentPageIndex = value;
}

}
}
/// <summary>
/// 每页显示的记录条数
/// </summary>
public int PageSize
{
get { return pageSize; }
set { pageSize = value; }
}
/// <summary>
/// 总页码
/// </summary>
public int PageCount
{
get { return (ItemCount - 1) / PageSize + 1; }
}
/// <summary>
/// 总记录条数
/// </summary>
public int ItemCount
{
get { return itemCount; }
set { itemCount = value; }
}
/// <summary>
/// 数据源
/// </summary>
public override object DataSource
{
set
{
try
{
//IList是非泛型列表,以防控件的数据源未实现ICollection接口
dataSource = (IList)value;
ItemCount = dataSource.Count;
}
catch
{
dataSource = null;
ItemCount = 0;
}
}
}
/// <summary>
/// 零记录提示字符串
/// </summary>
public string EmptyText
{
set { emptyText = value; }
}
/// <summary>
/// 加载事件,可以添加需要的处理代码,在这个例子里并未做任何处理
/// </summary>
/// <param name="e"></param>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
/// <summary>
/// 呈现事件,实现了页码方面的链接和统计,并且简单做了格式处理
/// </summary>
/// <param name="writer"></param>
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.Write("<div style=\"width:500px;border:solid 1px #444444;\">");

writer.Write("<div style=\"border-bottom:solid 1px #444444;padding:10px 0px;\">");
if (ItemCount == 0)
{
writer.Write(emptyText);
}

base.Render(writer);

writer.Write("</div>");
writer.Write("<div sty