分享下repeater+存储过程+自定义控件源码
public partial class List : System.Web.UI.Page
{
List<CLModel.TLinksCLModel> tLinksCLModel = new List<CLModel.TLinksCLModel>();
//展示友情链接数据提供
public int pcount = 0; //总条数
protected string pageLable = "";
protected int nowPage = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["page"]))
{
nowPage = int.Parse(Request.QueryString["page"]);
}
LoadContentList( nowPage);
}
//生成页面条
private void LoadContentList( int nPage)
{
int intRowCount = 0;
int intPageCount = 0;
int pageSize=10;
//使用 存储过程 执行分页【参数---当前页码,页容量,总行数(输出参数),总页数(输出参数)】
List<CLModel.TLinksCLModel> list = new CLBLL.TLinksCLBLL().QueryListByPageIndexPro(nPage, pageSize, out intRowCount, out intPageCount);
//生成页码条【参数---连接地址,查询条件,总行数,总页数,当前页码,页码组容量,页容量】
pageLable = WebHelper.GetPageTxt("List.aspx?&page=", "", intRowCount, intPageCount, nPage, 5, 3);
if(list!=null)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = list;
pds.AllowPaging = false;
pds.PageSize = pageSize;
int curPage;
if (Request.QueryString["page"] != null)
{
curPage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curPage = 1;
}
pds.CurrentPageIndex = curPage-1;
this.rptList.DataSource = pds;
this.rptList.DataBind();
}
}
}
#region +获得功能页码条
/// <summary>
/// 获得功能页码条
/// </summary>
/// <param name="url">页码连接地址</param>
/// <param name="searcheurl">搜索url</param>
/// <param name="allrecord">全部记录条数</param>
/// <param name="allpage">全部页面数</param>
/// <param name="curpage">当前页码</param>
/// <param name="groupsize">页码组大小</param>
/// <param name="pagesize">页容量</param>
public static string GetPageTxt(string url, string searcheurl, int allrecord, int allpage, int curpage, int groupsize, int pagesize)
{
int curGroupPage = 0;
StringBuilder test = new StringBuilder();
StringBuilder test2 = new StringBuilder();
StringBuilder pagetxt = new StringBuilder();
if (curpage.Equals("") || curpage < 1) curpage = 1;
if (allrecord.Equals("") || allrecord < 1) allrecord = 1;
if (pagesize.Equals("") || pagesize < 1) pagesize = 1;
if (allrecord == 0) { pagetxt.Append("页码:0/0 │ 共0条</TD> <td align='left'> 首页 << 上一页 | 1 Next | >> 尾页 </td></tr></table>"); }
else
{
test2.Append(allpage.ToString());
int tempI = 0;
tempI = curGroupPage;
do
{
if (tempI == curpage) pagetxt.Append("<span class='nowpage'>" + tempI + "</span> ");
else pagetxt.Append("<A href='" + url + tempI + searcheurl + "'>" + tempI + "</A> ");
tempI = tempI + 1;
} while (tempI < curGroupPage + groupsize && tempI <= allpage);
AS
begin
DECLARE @sql NVARCHAR(max),@sqlCount NVARCHAR(225)
select @RowCount =COUNT(FId),@PageCount=CEILING((COUNT(FId)+0.0)/@PageSize) FROM TLinks
SET @sql='SELECT TOP '+LTRIM(str(@PageSize))+' * FROM TLinks where FId not in(select top '+LTRIM(str((@PageIndex-1)*@PageSize))+' FId from TLinks order by FSortId DESC , FAddTime ASC)order by FSortId DESC , FAddTime ASC'
print @sql
EXEC(@sql)
end