码迷,mamicode.com
首页 > Web开发 > 详细

AspNetPager使用方法

时间:2016-01-03 02:38:50      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

AspNetPager使用方法:


1、首先引用AspNetPager.dll;

2、在所使用的前台页面加入:<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>,

指明DLL地址和命名空间;

3、在页面使用aspnetPager控件:(根据情况,自定义下面的属性)

<webdiyer:AspNetPager ID="AspNetPager1" class="quotes" runat="server" CustomInfoHTML="&lt;span class=&quot;pageDesc&quot;&gt;共有 %RecordCount%页 %CurrentPageIndex% / %PageCount% 页&lt;/span&gt;"

FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" Width="95%"

CustomInfoStyle="" PagingButtonsClass="PageButton" AlwaysShowFirstLastPageNumber="True"

CurrentPageButtonClass="PageButtonCurrent" PagingButtonSpacing="2px" PagingButtonsStyle=""

ShowPageIndexBox="Never" CurrentPageButtonStyle="" LayoutType="Table" OnPageChanging="AspNetPager1_PageChanging"

ShowCustomInfoSection="Left">

</webdiyer:AspNetPager>

标红的是点击触发事件:

在.cs后台页面加上此方法:

private void BindGridView(string searchTableName)


{


string sortExpression = gvInDepot.Attributes["SortExpression"] == null ? "Code" : gvInDepot.Attributes["SortExpression"];


bool isASCDirection = gvInDepot.Attributes["SortDirection"] == "ASC" ? true : false;

 

//int totalCounts = (int)SqlHelper.GetCountNumber(searchTableName, "ID", "1=1");


int totalCounts = SqlHelper.SelectTable("*", searchTableName, "1=1", "ID", true).Rows.Count;


AspNetPager1.RecordCount = totalCounts;


if (totalCounts > 0)


{


gvInDepot.DataSource = SqlHelper.GetPagedData(searchTableName, "1=1", sortExpression, isASCDirection, AspNetPager1.StartRecordIndex,

AspNetPager1.EndRecordIndex);


gvInDepot.DataBind();


}


else


{


ShowGridViewTitle();


}


}


写到这里运行的确是没问题了,但是点击翻页就发现数据都是一样的,为什么呢?的确我们忘记了一件事,分页改变事件:

 

protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{


int tableCount = 0;


string searchTable = creatSearchTable(out tableCount);


BindGridView(searchTable);


}



4、同时,还要指定以下值:

AspNetPager1.PageSize=10;//每页显示多少条记录

AspNetPager1.RecordCount=100;//总页数

5、因为该控件与数据显示和绑定是独立的,所以可以根据所要显示的页数AspNetPager1.CurrentPageIndex,取得该页数据datatable,然后再使用repeater等控件绑定:

Repeater1.DataSource = dt;

Repeater1.DataBind();

AspNetPager使用方法

标签:

原文地址:http://www.cnblogs.com/BrokenIce/p/5095605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!