一个很好用的分页控件,本来想将用户控件的时候说的,但是既然涉及到了,就简单的说下用法
控件大家可以找我要,小白和小贝也都有,也可以从这个地址下载:
http://download.csdn.net/detail/gongchuanbo/1258255
1.首先将dll文件添加引用
2.在aspx页面添加注册:
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
在需要的位置添加如下代码:
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged"
ShowCustomInfoSection="left" ShowInputBox="Auto" AlwaysShow="True" CustomInfoHTML="<font color='#333333'>共 %RecordCount% 行/每页%PageSize%行 第%CurrentPageIndex%/%PageCount%页 顺序 %StartRecordIndex%-%EndRecordIndex%</font> "
NumericButtonCount="10" FirstPageText="首页" LastPageText="末页" NextPageText="下页"
PrevPageText="上页" CustomInfoSectionWidth="65%" CssClass="page_text" ShowBoxThreshold="2"
InputBoxClass="pagetext" SubmitButtonClass="BtnStyle" SubmitButtonText="Go"
NavigationButtonType="Image">
</webdiyer:AspNetPager>
在控件的AspNetPager1_PageChanged事件中添加如下代码:
DataBindGride();
DataBindGride函数的代码如下:
Users u = new Users();
this.AspNetPager1.RecordCount = Int32.Parse(u.GetArticlCount().ToString());
int pageIndex = (this.AspNetPager1.CurrentPageIndex);
int pageSize = this.AspNetPager1.PageSize = 10;
this.GridView1.DataSource = u.GetArticleInfo(pageIndex, pageSize);
GridView1.DataBind();
其中u.GetArticlCount()方法获取表中总的记录行数,u.GetArticleInfo方法根据当前的页码和每页显示的记录数获取记录
在page_load中添加如下代码:
if (!IsPostBack)
{
DataBindGride();
}